Example #1
0
        public bool AddOrder()
        {
            int order_Id = 0;

            Order order = new Order()
            {
                OrderDate   = DateTime.Now,
                OrderNumber = string.Format("{0:ddmmyyyyHHmmsss}", DateTime.Now)
            };

            dataContext.Orders.Add(order);
            dataContext.SaveChanges();
            order_Id = order.OrderId;

            foreach (var item in shoppingCartModels)
            {
                OrderDetail orderDetail = new OrderDetail()
                {
                    OrderId   = order_Id,
                    ItemId    = item.ItemId,
                    Quantity  = item.Quantity,
                    Total     = item.Total,
                    UnitPrice = item.UnitPrice,
                };
                dataContext.OrderDetails.Add(orderDetail);
            }
            if (dataContext.SaveChanges() > 0)
            {
                return(true);
            }
            return(false);
        }
        public Item AddItem(ItemViewModel itemViewModel)
        {
            string newImage = Guid.NewGuid() + Path.GetExtension(itemViewModel.ItemImage.FileName);

            itemViewModel.ItemImage.SaveAs(HttpContext.Current.Server.MapPath("~/Images/" + newImage));
            Item itemToAdd = new Item();

            itemToAdd.ItemId      = Guid.NewGuid();
            itemToAdd.ItemName    = itemViewModel.ItemName;
            itemToAdd.ItemPrice   = itemViewModel.ItemPrice;
            itemToAdd.ItemCode    = itemViewModel.ItemCode;
            itemToAdd.Description = itemViewModel.Description;
            itemToAdd.CategoryId  = itemViewModel.CategoryId;
            itemToAdd.ImagePath   = "~/Images/" + newImage;
            dataContext.Items.Add(itemToAdd);
            if (dataContext.SaveChanges() > 0)
            {
                return(itemToAdd);
            }
            return(itemToAdd);
        }