Esempio n. 1
0
        /// <summary>
        /// Como User tendrá un borrado logico, para no entorpecer los detalles de la orden , esto lo que hará será actualizar el estado e indicar si está visible o no.
        /// </summary>
        ///
        public static void UpdateStatusLogic(User user)
        {
            ctx = new CheqStoreContext();

            user.StatusLogic      = !user.StatusLogic;
            ctx.Entry(user).State = EntityState.Modified;
            ctx.SaveChanges();
        }
 public static void UpdateStatusLogic(Category category)
 {
     using (ctx = new CheqStoreContext())
     {
         category.StatusLogic      = !category.StatusLogic;
         ctx.Entry(category).State = EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Esempio n. 3
0
        public static void DeleteOrder(int OrderID)
        {
            using (ctx = new CheqStoreContext())
            {
                Order order = ctx.Orders.Find(OrderID);

                ctx.Entry(order).State = System.Data.Entity.EntityState.Deleted;
                ctx.SaveChanges();
            }
        }
Esempio n. 4
0
        public static void UpdateTotal(CheqStoreContext ctx, int OrderID, decimal Total)
        {
            Order order = ctx.Orders.Find(OrderID);

            order.Total = Total;

            ctx.Entry(order).State = System.Data.Entity.EntityState.Modified;

            ctx.SaveChanges();
        }
Esempio n. 5
0
        public static void UpdateUser(User user)
        {
            User   originalUser = GetByID(user.UserID);
            string Password     = originalUser.Password;

            using (ctx = new CheqStoreContext())
            {
                user.Password = (string.IsNullOrWhiteSpace(user.Password)) ? Password: CredentialsRepository.EncryptingPassword(user.Password);

                ctx.Entry(user).State = System.Data.Entity.EntityState.Modified;
                ctx.SaveChanges();
            }
        }
Esempio n. 6
0
        public static bool DeleteProduct(CheqStoreContext ctx, Product product)
        {
            bool AnyProductInOrder = ctx.OrderDetails.Any(x => x.ProductID == product.ProductID);

            if (AnyProductInOrder)
            {
                return(false);
            }

            ctx.Entry(product).State = EntityState.Deleted;
            ctx.SaveChanges();
            return(true);
        }
        public static bool DeleteCategory(Category category)
        {
            ctx = new CheqStoreContext();
            bool AnyProductInCategory = ctx.Products.Any(x => x.CategoryID == category.CategoryID);

            if (AnyProductInCategory)
            {
                return(false);
            }

            ctx.Entry(category).State = EntityState.Deleted;
            ctx.SaveChanges();
            return(true);
        }
Esempio n. 8
0
        public ActionResult Edit([Bind(Include = "CategoryID,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                if (db.Categories.Any(x => x.Name == category.Name && x.CategoryID != category.CategoryID))
                {
                    TempData["Message"] = "No puede repetir el nombre en cheqstore";

                    return(RedirectToAction("Index"));
                }
                db.Entry(category).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(category));
        }
Esempio n. 9
0
        public static void UpdateOrder(CheqStoreContext ctx, Order order)
        {
            using (ctx)
            {
                order.Status = !order.Status;

                if (order.Status)
                {
                    order.ConfirmedDate = DateTime.Now;
                }
                else
                {
                    order.ConfirmedDate = null;
                }

                ctx.Entry(order).State = System.Data.Entity.EntityState.Modified;
                ctx.SaveChanges();
            }
        }
Esempio n. 10
0
        public static bool DeleteUser(User user)
        {
            try
            {
                ctx = new CheqStoreContext();

                bool hadOrders = ctx.Orders.Any(x => x.UserID == user.UserID);

                if (hadOrders)
                {
                    return(false);
                }

                ctx.Entry(user).State = EntityState.Deleted;
                ctx.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return(false);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Descuento cantidad al producto, en caso de que exceda me devuelve false y no se efectuará la compra, de lo contrario devolverá true.
        /// </summary>
        /// <param name="ProductID"></param>
        /// <param name="Quantity"></param>
        /// <returns></returns>
        public static bool SubstractStock(CheqStoreContext ctx, int ProductID, int Quantity)
        {
            Product product = ctx.Products.Find(ProductID);

            if (!IsThereStockToProcess(ProductID, Quantity))
            {
                return(false);
            }

            try
            {
                product.Stock           -= Quantity;
                ctx.Entry(product).State = EntityState.Modified;
                ctx.SaveChanges();

                return(true);
            }
            catch (Exception e)
            {
                Debug.WriteLine("El error es ->" + e.Message);
                return(false);
            }
        }
Esempio n. 12
0
        public static void UpdateProduct(Product product, HttpPostedFileBase File)
        {
            ctx = new CheqStoreContext();

            var OriginalProduct = ValidationProduct.getRecordFromID(product.ProductID);

            if (product.CreatedAt == null)
            {
                product.CreatedAt = OriginalProduct.CreatedAt;
            }

            if (File == null)
            {
                product.PathPhoto = OriginalProduct.PathPhoto;
            }
            else
            {
                product.PathPhoto = MultimediaRepository.uploadImage(File);
            }
            product.Stock            = product.Stock > 0 ? product.Stock : 0;
            product.StatusLogic      = product.Stock > 0 ? true : false;
            ctx.Entry(product).State = EntityState.Modified;
            ctx.SaveChanges();
        }
Esempio n. 13
0
 /// <summary>
 /// Como producto tendrá un borrado logico, para no entorpecer los detalles de la orden y orden detail, esto lo que hará será actualizar el estado e indicar si está visible o no.
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="product"></param>
 ///
 public static void UpdateStatusLogic(CheqStoreContext ctx, Product product)
 {
     product.StatusLogic      = !product.StatusLogic;
     ctx.Entry(product).State = EntityState.Modified;
     ctx.SaveChanges();
 }