Пример #1
0
        public void UpdateCategory(Category category)
        {
            eCommerceContext context = new eCommerceContext();

            context.Entry(category).State = System.Data.Entity.EntityState.Modified;

            context.SaveChanges();
        }
Пример #2
0
        public bool AddOrderHistory(OrderHistory orderHistory)
        {
            eCommerceContext context = new eCommerceContext();

            context.OrderHistories.Add(orderHistory);

            return(context.SaveChanges() > 0);
        }
Пример #3
0
        public void SaveProduct(Product Product)
        {
            eCommerceContext context = new eCommerceContext();

            context.Products.Add(Product);

            context.SaveChanges();
        }
Пример #4
0
        public void UpdateSupplier(Supplier supplier)
        {
            eCommerceContext context = new eCommerceContext();

            context.Entry(supplier).State = System.Data.Entity.EntityState.Modified;

            context.SaveChanges();
        }
Пример #5
0
        public bool SaveOrder(Order order)
        {
            eCommerceContext context = new eCommerceContext();

            context.Orders.Add(order);

            return(context.SaveChanges() > 0);
        }
Пример #6
0
        public void SavePromo(Promo Promo)
        {
            eCommerceContext context = new eCommerceContext();

            context.Promos.Add(Promo);

            context.SaveChanges();
        }
Пример #7
0
        public void SaveSupplier(Supplier supplier)
        {
            eCommerceContext context = new eCommerceContext();

            context.Suppliers.Add(supplier);

            context.SaveChanges();
        }
Пример #8
0
        public bool AddComment(Comment comment)
        {
            eCommerceContext context = new eCommerceContext();

            context.Comments.Add(comment);

            return(context.SaveChanges() > 0);
        }
Пример #9
0
        public void UpdateConfiguration(Configuration configuration)
        {
            eCommerceContext context = new eCommerceContext();

            context.Entry(configuration).State = System.Data.Entity.EntityState.Modified;

            context.SaveChanges();
        }
Пример #10
0
        public void SaveCategory(Category category)
        {
            eCommerceContext context = new eCommerceContext();

            context.Categories.Add(category);

            context.SaveChanges();
        }
Пример #11
0
        public void UpdatePromo(Promo Promo)
        {
            eCommerceContext context = new eCommerceContext();

            var exitingPromo = context.Promos.Find(Promo.ID);

            context.Entry(exitingPromo).CurrentValues.SetValues(Promo);

            context.SaveChanges();
        }
Пример #12
0
        public int SavePicture(Picture picture)
        {
            eCommerceContext context = new eCommerceContext();

            context.Pictures.Add(picture);

            context.SaveChanges();

            return(picture.ID);
        }
Пример #13
0
        public Payment AddUserPayment(Payment payment)
        {
            eCommerceContext context = new eCommerceContext();

            var paymentToAdd = context.Payment.Add(payment);

            context.SaveChanges();

            return(paymentToAdd);
        }
Пример #14
0
        public bool DeleteSupplier(int ID)
        {
            using (var context = new eCommerceContext())
            {
                var supplier = context.Suppliers.Find(ID);

                context.Suppliers.Remove(supplier);

                return(context.SaveChanges() > 0);
            }
        }
Пример #15
0
        public bool DeleteCategory(int ID)
        {
            using (var context = new eCommerceContext())
            {
                var category = context.Categories.Find(ID);

                context.Categories.Remove(category);

                return(context.SaveChanges() > 0);
            }
        }
Пример #16
0
        public bool DeletePromo(int ID)
        {
            using (var context = new eCommerceContext())
            {
                var promo = context.Promos.Find(ID);

                context.Promos.Remove(promo);

                return(context.SaveChanges() > 0);
            }
        }
Пример #17
0
        public void UpdateConfigurationValue(string key, string value)
        {
            eCommerceContext context = new eCommerceContext();

            var configuration = context.Configurations.Find(key);

            configuration.Value = value;

            context.Entry(configuration).State = System.Data.Entity.EntityState.Modified;

            context.SaveChanges();
        }
Пример #18
0
        public bool DeleteComment(int ID)
        {
            eCommerceContext context = new eCommerceContext();

            var comment = context.Comments.Find(ID);

            if (comment != null)
            {
                context.Entry(comment).State = System.Data.Entity.EntityState.Deleted;
            }
            return(context.SaveChanges() > 0);
        }
Пример #19
0
 public IActionResult AddingProduct(Product product)
 {
     if (ModelState.IsValid)
     {
         _context.products.Add(product);
         _context.SaveChanges();
         return(RedirectToAction("AllProducts"));
     }
     else
     {
         return(View("AddProduct"));
     }
 }
Пример #20
0
 public IActionResult AddingCustomer(Customer customer)
 {
     if (ModelState.IsValid)
     {
         customer.created_at = DateTime.Now;
         _context.customers.Add(customer);
         _context.SaveChanges();
         return(RedirectToAction("AllCustomers"));
     }
     else
     {
         return(View("AddCustomer"));
     }
 }
Пример #21
0
        public IActionResult AddingToOrder(int productid, int quantity, int customerid)
        {
            TempData["CustomerId"] = TempData["CustomerId"];
            List <Cart_Item> CartItems = _context.cart_items.Where(c => c.customer_id == customerid).Where(c => c.product_id == productid).ToList();

            if (CartItems.Count() > 0)
            {
                Cart_Item CurrentCartItem = CartItems.First();
                CurrentCartItem.product_quantity += quantity;
                _context.SaveChanges();
                return(RedirectToAction("AllOrders"));
            }
            else
            {
                Cart_Item InstallingCartItem = new Cart_Item();
                InstallingCartItem.customer_id      = customerid;
                InstallingCartItem.product_id       = productid;
                InstallingCartItem.product_quantity = quantity;
                _context.cart_items.Add(InstallingCartItem);
                _context.SaveChanges();
                return(RedirectToAction("AllOrders"));
            }
        }
Пример #22
0
        public void UpdateProduct(Product Product)
        {
            eCommerceContext context = new eCommerceContext();

            var exitingProduct = context.Products.Find(Product.ID);

            context.ProductPictures.RemoveRange(exitingProduct.ProductPictures);
            context.ProductSpecifications.RemoveRange(exitingProduct.ProductSpecifications);
            context.ProductCosts.RemoveRange(exitingProduct.ProductCosts);

            context.Entry(exitingProduct).CurrentValues.SetValues(Product);

            context.ProductPictures.AddRange(Product.ProductPictures);
            context.ProductSpecifications.AddRange(Product.ProductSpecifications);
            context.ProductCosts.AddRange(Product.ProductCosts);

            context.SaveChanges();
        }
Пример #23
0
 public bool SaveChanges()
 {
     try
     {
         if (_context.SaveChanges() > 0)
         {
             return(true);
         }
         return(false);
     }
     catch (DbEntityValidationException ex)
     {
         foreach (var validationMessages in ex.EntityValidationErrors)
         {
             foreach (var validationError in validationMessages.ValidationErrors)
             {
                 errorMessage += Environment.NewLine + string.Format("Property : {0} Error : {1}", validationError.PropertyName, validationError.ErrorMessage);
             }
         }
         throw new Exception(errorMessage, ex);
         //return false;
     }
 }
Пример #24
0
        public static ShoppingCartItem AddItem(AddItemDto item, eCommerceContext _context)
        {
            if (!_context.Product.Any(x => x.ProductId == item.ProductId))
            {
                return(null);
            }

            if (item.Quantity <= 0)
            {
                return(null);
            }

            API.Models.ShoppingCart cart = _context.ShoppingCart.FirstOrDefault(x => x.ShoppingCartId == item.ShoppingCartID);

            if (cart == null)
            {
                cart = new API.Models.ShoppingCart()
                {
                    LastUpdated = DateTime.Now
                }
            }
            ;

            var cartItem = new ShoppingCartItem()
            {
                ProductId = item.ProductId ?? 0,
                Quantity  = item.Quantity ?? 0
            };

            cart.ShoppingCartItem = new[] { cartItem };

            _context.SaveChanges();

            return(cartItem);
        }
    }
Пример #25
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }