public static User GetByID(int ID) { using (ctx = new CheqStoreContext()) { return(ctx.Users.Find(ID)); } }
public static void UpdateStatus(int OrderID) { ctx = new CheqStoreContext(); var Order = ctx.Orders.Find(OrderID); UpdateOrder(ctx, Order); }
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")); } } }
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")); } }
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")); } }
public static void StoreUser(User user) { ctx = new CheqStoreContext(); user.Password = CredentialsRepository.EncryptingPassword(user.Password); ctx.Users.Add(user); ctx.SaveChanges(); }
/// <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(); } }
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(); } }
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(); }
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(); }
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()); }
/// <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); }
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(); } }
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); }
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(); } }
/// <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); } }
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); } }
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(); }
/// <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(); }
public static Order GetByID(int id) { ctx = new CheqStoreContext(); return(ctx.Orders.FirstOrDefault(x => x.ID == id)); }
public static void StoreOrder(CheqStoreContext ctx, Order order) { ctx.Orders.Add(order); ctx.SaveChanges(); }