Exemple #1
0
 public static User GetByID(int ID)
 {
     using (ctx = new CheqStoreContext())
     {
         return(ctx.Users.Find(ID));
     }
 }
Exemple #2
0
        public static void UpdateStatus(int OrderID)
        {
            ctx = new CheqStoreContext();
            var Order = ctx.Orders.Find(OrderID);

            UpdateOrder(ctx, Order);
        }
Exemple #3
0
        public ActionResult Delete(int?id)
        {
            using (db = new CheqStoreContext())
            {
                try
                {
                    if (id == null)
                    {
                        TempData["Message"] = "Debe ingresar un ID valido de Categoria para eliminar";

                        return(RedirectToAction("Index"));
                    }

                    Category category = db.Categories.Find(id);

                    if (!RepositoryCategories.DeleteCategory(category))
                    {
                        TempData["Message"] = "No puede eliminar una categoria con productos, debe eliminar o cambiar de categoria antes los productos dependientes";

                        return(RedirectToAction("Index"));
                    }

                    TempData["Message"] = "Eliminacion correcta";

                    return(RedirectToAction("Index"));
                }

                catch (Exception e)
                {
                    TempData["Message"] = "Problema al cambiar estado -> " + e.Message;

                    return(RedirectToAction("Index"));
                }
            }
        }
Exemple #4
0
        public ActionResult ChangeStatusLogic(int?id)
        {
            CheqStoreContext ctx = new CheqStoreContext();

            try
            {
                if (id == null)
                {
                    TempData["Message"] = "Debe ingresar un ID valido de User para cambiar su estado";

                    return(RedirectToAction("Index"));
                }

                User user = ctx.Users.Find(id);

                UserRepository.UpdateStatusLogic(user); //Actualizo el borrado logico

                TempData["Message"] = "Cambio de estado correcto";

                return(RedirectToAction("Index"));
            }

            catch (Exception e)
            {
                TempData["Message"] = "Problema al cambiar estado -> " + e.Message;

                return(RedirectToAction("Index"));
            }
        }
Exemple #5
0
        public ActionResult Delete(int?id)
        {
            CheqStoreContext ctx = new CheqStoreContext();

            try
            {
                if (id == null)
                {
                    TempData["Message"] = "Debe ingresar un ID valido de user para eliminar";

                    return(RedirectToAction("Index"));
                }

                User user = ctx.Users.Find(id);

                if (!UserRepository.DeleteUser(user))
                {
                    TempData["Message"] = "No puede eliminar un user que ya tenga ordenes pedidas.";

                    return(RedirectToAction("Index"));
                }

                TempData["Message"] = "Eliminacion correcta";

                return(RedirectToAction("Index"));
            }

            catch (Exception e)
            {
                TempData["Message"] = "Problema al cambiar estado -> " + e.Message;

                return(RedirectToAction("Index"));
            }
        }
Exemple #6
0
        public static void StoreUser(User user)
        {
            ctx = new CheqStoreContext();

            user.Password = CredentialsRepository.EncryptingPassword(user.Password);
            ctx.Users.Add(user);
            ctx.SaveChanges();
        }
Exemple #7
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();
     }
 }
Exemple #9
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();
            }
        }
Exemple #10
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();
        }
Exemple #11
0
        public static void StoreProduct(Product product, HttpPostedFileBase File)
        {
            ctx = new CheqStoreContext();

            product.PathPhoto   = MultimediaRepository.uploadImage(File);
            product.CreatedAt   = DateTime.Now;
            product.Stock       = product.Stock > 0 ? product.Stock : 0;
            product.StatusLogic = product.Stock > 0 ? true : false;
            ctx.Products.Add(product);
            ctx.SaveChanges();
        }
Exemple #12
0
        public static List <Product> ListProductFromCategory(string Category)
        {
            ctx = new CheqStoreContext();

            if (!ctx.Categories.Any(c => c.Name == Category) || string.IsNullOrEmpty(Category))
            {
                return(ctx.Products.Where(p => p.StatusLogic == true && p.Stock > 0).ToList());
            }

            return(ctx.Products.Where(p => p.Category.Name == Category && p.StatusLogic == true && p.Stock > 0).ToList());
        }
Exemple #13
0
        /// <summary>
        /// Pregunto si existe la cantidad suficiente como para procesar la solicitud.
        /// </summary>
        /// <param name="ProductID"></param>
        /// <param name="Quantity"></param>
        /// <returns></returns>
        public static bool IsThereStockToProcess(int ProductID, int Quantity)
        {
            ctx = new CheqStoreContext();
            Product product = ctx.Products.Find(ProductID);

            if (product.Stock - Quantity >= 0)
            {
                return(true);
            }

            return(false);
        }
Exemple #14
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();
            }
        }
Exemple #15
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);
        }
Exemple #17
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();
            }
        }
Exemple #18
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);
            }
        }
Exemple #19
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);
            }
        }
Exemple #20
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();
        }
Exemple #21
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();
 }
Exemple #22
0
        public static Order GetByID(int id)
        {
            ctx = new CheqStoreContext();

            return(ctx.Orders.FirstOrDefault(x => x.ID == id));
        }
Exemple #23
0
 public static void StoreOrder(CheqStoreContext ctx, Order order)
 {
     ctx.Orders.Add(order);
     ctx.SaveChanges();
 }