Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. I'm trying to create a simple ecommerce, but i'm in trouble. Here's my code until now.




Classes:



C#
public class Design
{
    [Key]
    public int DesignId { get; set; }
    public String name{ get; set; }
    public Decimal price{ get; set; }

    public virtual ICollection<ItemDesign> ItemDesign { get; set; }
}

public class ItemDesign
{
    [Key]
    public int ItemDesignId { get; set; }
    public int DesignId { get; set; }
    public int OrderId{ get; set; }

    public virtual Design Design { get; set; }
    public virtual Order Order { get; set; }
}

public class Pedido
{
    [Key]
    public int OrderId { get; set; }
    public int UserId { get; set; }
    public DateTime DtOrder { get; set; }
    public StatusOrder StatusOrder { get; set; }
    public string Username {get; set;}
    public string TypePayment {get; set;}
    public DateTime DtPayment { get; set; }
    public Decimal TotalPrice { get; set; }

    public virtual User User { get; set; }
    public virtual ICollection<ItemDesign> ItemDesign { get; set; }
}



Actions:

C#
public ActionResult AddCart(int id)
  {

      Order cart = Session["Cart"] != null ? (Order)Session["Cart"] : new Order();

      var design = db.Design.Find(id);

      if (design != null)
      {
          var itemDesign = new ItemDesign();
          itemDesign.Design = design;
          itemDesign.Qtd = 1;

          if (cart.ItemDesign.FirstOrDefault(x => x.IdDesign == design.IdDesign) != null)
          {
              cart.ItemDesign.FirstOrDefault(x => x.IdDesign == design.IdDesign).Qtd += 1;
          }

          else
          {
              cart.ItemDesign.Add(itemDesign);
          }


          cart.ValorTotal = cart.ItemDesign.Select(i => i.Design).Sum(d => d.price);

          Session["cart"] = cart;
      }

      return RedirectToAction("cart");
  }

  public ActionResult Cart()
  {
      Order cart = Session["cart"] != null ? (Order)Session["cart"] : new Order();

      return View(cart);
  }


My trouble is, I'm lost after the creation of the cart. How can I'm going to save the cart in the database? And, how can I make a checkout? I want the user insert his name and the way of payment. Them, I want to save the order, and the cart in the database. Anyone can help?
Posted
Updated 22-Nov-14 16:50pm
v3

1 solution

Go through https://nopcommerce.codeplex.com[^]. You will find demo of each functionality.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900