Exemplo n.º 1
0
 public static List<CartItemViewModel> CreateList(List<CartItem> lstCartItem)
 {
     assignment1Entities db = new assignment1Entities();
     List<CartItemViewModel> lstCartItemVM = new List<CartItemViewModel>();
     foreach(CartItem cartItem in lstCartItem)
     {
         CartItemViewModel cartItemVM = new CartItemViewModel();
         cartItemVM.Color = cartItem.Color;
         MobilePhone mobile = db.MobilePhones.Where(n => n.MobileID == cartItem.MobileID).SingleOrDefault();
         cartItemVM.MobileName = mobile.MobileName;
         cartItemVM.Price = String.Format("{0:0,0 vnđ}", mobile.Price);
         lstCartItemVM.Add(cartItemVM);
     }
     return lstCartItemVM;
 }
Exemplo n.º 2
0
        public static List <CartItemViewModel> CreateList(List <CartItem> lstCartItem)
        {
            assignment1Entities      db            = new assignment1Entities();
            List <CartItemViewModel> lstCartItemVM = new List <CartItemViewModel>();

            foreach (CartItem cartItem in lstCartItem)
            {
                CartItemViewModel cartItemVM = new CartItemViewModel();
                cartItemVM.Color = cartItem.Color;
                MobilePhone mobile = db.MobilePhones.Where(n => n.MobileID == cartItem.MobileID).SingleOrDefault();
                cartItemVM.MobileName = mobile.MobileName;
                cartItemVM.Price      = String.Format("{0:0,0 vnđ}", mobile.Price);
                lstCartItemVM.Add(cartItemVM);
            }
            return(lstCartItemVM);
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            assignment1Entities db = new assignment1Entities();
            User user = (User)Session["User"];
            if (user == null)
                Response.Redirect("Register.aspx");
            CartOnline cartOnl = (CartOnline)Session["CartOnl"];
            if (cartOnl == null)
                Response.Redirect("Home.aspx");
            Cart cart = new Cart();
            cart.CreatedDate = DateTime.UtcNow;
            cart.CustomerID = user.UserID;
            cart.Quantity = cartOnl.lstSP.Count;
            cart.TypePayment = "Online";
            cart.Status = "Processing";
            cart.DateTranfer = cartOnl.DateTransfer;
            db.Carts.Add(cart);
            db.SaveChanges();

            string s = Server.MapPath("xml");
            string fileName = user.LastName + user.FirstName + "_" + cart.CartID;
            string path_file = string.Format("{0}/{1}.xml", s, fileName);
            XmlTextWriter xtw = new XmlTextWriter(path_file, System.Text.Encoding.UTF8);
            xtw.Formatting = Formatting.Indented;
            xtw.WriteStartDocument();
            xtw.WriteStartElement("Cart");
            xtw.WriteStartElement("CustomerInformation");
            xtw.WriteStartElement("CustomerName");
            xtw.WriteString(user.LastName + " " + user.FirstName);
            xtw.WriteEndElement();
            xtw.WriteStartElement("CustomerEmail");
            xtw.WriteString(user.Email);
            xtw.WriteEndElement();
            xtw.WriteStartElement("CustomerPhone");
            xtw.WriteString(user.Phone);
            xtw.WriteEndElement();
            xtw.WriteStartElement("CustomerAddress");
            xtw.WriteString(user.Address);
            xtw.WriteEndElement();
            xtw.WriteStartElement("DateTransfer");
            xtw.WriteString(cartOnl.DateTransfer.ToString());
            xtw.WriteEndElement();
            xtw.WriteStartElement("DateCreated");
            xtw.WriteString(DateTime.Now.ToString());
            xtw.WriteEndElement();
            xtw.WriteEndElement();
            int index = 0;
            int? total = 0;

            List<ShoppingCart> lst = cartOnl.lstSP;
            int count = lst.Count;
            for (int i = 0; i < count; i++)
            {
                string color = lst[i].color;
                createNode(lst[index].ProductID.ToString(), lst[index].ProductName, lst[index].Price.ToString(), color, lst[index].timeInsurance.ToString(), xtw);
                total += lst[index].Price;
                CartItem cartItem = new CartItem();
                cartItem.MobileID = lst[index].ProductID;
                cartItem.CartID = cart.CartID;
                cartItem.Color = color;
                db.CartItems.Add(cartItem);
                int id = int.Parse(lst[index].ProductID.ToString());
                MobilePhone mobile = db.MobilePhones.Where(n => n.MobileID == id).SingleOrDefault();
                mobile.Quantity--;
                db.SaveChanges();
                index++;
            }
            cart.TotalPrice = total;
            db.SaveChanges();
            xtw.WriteEndElement();
            xtw.WriteEndDocument();
            xtw.Flush();
            xtw.Close();
            Session["ShoppingCart"] = null;
            Session["CartOnline"] = null;
            Response.Redirect("Home.aspx");
        }