Ejemplo n.º 1
0
        public ActionResult Edit(int id, Category category)
        {
            Category _category = chocoPlanetDbEntities.Category.SingleOrDefault(c => c.ID == category.ID);

            _category.Name = category.Name;
            chocoPlanetDbEntities.SaveChanges();
            return(RedirectToAction("CategoryCatalog"));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id, Order ordersInfo)
        {
            Order order = chocoPlanetDbEntities.Order.SingleOrDefault(o => o.ID == ordersInfo.ID);

            order.ModifayDate                   = DateTime.Now;
            order.StatusId                      = ordersInfo.StatusId;
            order.Customer.Name                 = ordersInfo.Customer.Name;
            order.Customer.Telefon              = ordersInfo.Customer.Telefon;
            order.Customer.Address.Stret        = ordersInfo.Customer.Address.Stret;
            order.Customer.Address.Town         = ordersInfo.Customer.Address.Town;
            order.Customer.Address.Country.Name = ordersInfo.Customer.Address.Country.Name;
            chocoPlanetDbEntities.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public ActionResult Edit(int id, Product product, string photo_filename)
        {
            Product _product = chocoPlanetDbEntities.Product.SingleOrDefault(p => p.ID == product.ID);

            _product.Name = product.Name;
            if (!String.IsNullOrEmpty(photo_filename))
            {
                _product.Foto = _fileStore.UploadFolderAbsolute + photo_filename;
            }
            _product.Price       = product.Price;
            _product.Description = product.Description;
            _product.categoryID  = product.categoryID;

            chocoPlanetDbEntities.SaveChanges();
            return(RedirectToAction("SecurityProductCatalog"));
        }
Ejemplo n.º 4
0
        public void CreateOrder(Cart cart)
        {
            int     statusID     = chocoPlanetDbEntities.Status.SingleOrDefault(s => s.Name == "Новий").ID;
            int     orderItemsID = (chocoPlanetDbEntities.OrderItems.Count() != 0) ? (chocoPlanetDbEntities.OrderItems.Max(id => id.ID) + 1) : 1;
            Country country      = new Country()
            {
                ID   = (chocoPlanetDbEntities.Country.Count() != 0) ? chocoPlanetDbEntities.Country.Max(id => id.ID) + 1 : 1,
                Name = cart.ShippingDetails.Country
            };
            Address address = new Address()
            {
                ID        = (chocoPlanetDbEntities.Address.Count() != 0) ? chocoPlanetDbEntities.Address.Max(id => id.ID) + 1 : 1,
                CountryId = country.ID,
                Town      = cart.ShippingDetails.Town,
                Stret     = cart.ShippingDetails.Stret
            };
            Customer customer = new Customer()
            {
                ID        = (chocoPlanetDbEntities.Customer.Count() != 0) ? chocoPlanetDbEntities.Customer.Max(id => id.ID) + 1 : 1,
                Name      = cart.ShippingDetails.Name,
                Telefon   = cart.ShippingDetails.Telefon,
                AddressId = address.ID
            };
            Order order = new Order()
            {
                ID          = (chocoPlanetDbEntities.Order.Count() != 0) ? chocoPlanetDbEntities.Order.Max(id => id.ID) + 1 : 1,
                StatusId    = statusID,
                CreateDate  = DateTime.Now,
                ModifayDate = DateTime.Now,
                CustomerId  = customer.ID
            };


            foreach (CartLine line in cart.Lines)
            {
                OrderItems orderItems = new OrderItems();
                orderItems.ID        = orderItemsID;
                orderItems.OrderId   = order.ID;
                orderItems.ProductId = chocoPlanetDbEntities.Product.SingleOrDefault(name => name.Name == line.Product.Name).ID;
                orderItems.Quantity  = line.Quantity;
                chocoPlanetDbEntities.OrderItems.AddObject(orderItems);
                orderItemsID++;
            }
            chocoPlanetDbEntities.Order.AddObject(order);
            chocoPlanetDbEntities.Country.AddObject(country);
            chocoPlanetDbEntities.Customer.AddObject(customer);
            chocoPlanetDbEntities.Address.AddObject(address);
            chocoPlanetDbEntities.SaveChanges();
        }