public ActionResult Create(Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
/// <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 StoreUser(User user) { ctx = new CheqStoreContext(); user.Password = CredentialsRepository.EncryptingPassword(user.Password); ctx.Users.Add(user); 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 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 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 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 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 ResponseEntity StoreRegister(RegisterRequest registerRequest) { if (CredentialsRepository.busyUsername(registerRequest.Username)) { return responseEntity = new ResponseEntity() { status = false, message = "El usuario ya está ocupado, pruebe con otro por favor" } } ; try { User userEntity = new User() { Name = registerRequest.Name, Username = registerRequest.Username, Password = CredentialsRepository.EncryptingPassword(registerRequest.Password), }; ctx.Users.Add(userEntity); ctx.SaveChanges(); return(responseEntity = new ResponseEntity() { status = true, message = "" }); } catch (Exception e) { return(responseEntity = new ResponseEntity() { status = false, message = "Error al grabar el usuario desde register, -> " + e.Message }); } } }
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(); }
public static void StoreOrder(CheqStoreContext ctx, Order order) { ctx.Orders.Add(order); 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(); }