购物车和结帐Asp.net MVC [英] Shopping Cart and Checkout Asp.net MVC

查看:131
本文介绍了购物车和结帐Asp.net MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我正在尝试创建一个简单的电子商务,但我遇到了麻烦。这是我的代码,直到现在。









课程:







Hi. I'm trying to create a simple ecommerce, but i'm in trouble. Here's my code until now.




Classes:



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:

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?

推荐答案

浏览 https://nopcommerce.codeplex.com [ ^ ]。您将找到每个功能的演示。
Go through https://nopcommerce.codeplex.com[^]. You will find demo of each functionality.


这篇关于购物车和结帐Asp.net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆