public ActionResult Create([Bind(Include = "Id,BarcodeNumber,Name,PurchasePrice,SellingPrice,MadeInCountry,ProductionDate,ExpiryDate,HasGuarantee,CategoryId,SupplierId,CreatedDate,CreatedBy,UpdatedDate,UpdatedBy,IsArchived,Quentity")] Product product) { if (ModelState.IsValid) { var maybe = _productManger.GetAllBind().Where(c => c.CategoryId == product.CategoryId && c.IsArchived == false); if (maybe.FirstOrDefault() == null) { Category category = _categoryManger.GetBy(product.CategoryId); category.HiddInMenu = false; _categoryManger.Save(); } product.CreatedDate = DateTime.Now; product.UpdatedDate = DateTime.Now; product.CreatedBy = HttpContext.Request.UserHostAddress + "/" + User.Identity.Name + "/" + Request.LogonUserIdentity.Name; product.UpdatedBy = HttpContext.Request.UserHostAddress + "/" + User.Identity.Name + "/" + Request.LogonUserIdentity.Name; setCategoryAndSupplierlist(); _productManger.Add(product); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult DeleteConfirmed(int id) { Category category = _CategoryManger.GetBy(id); category.IsArchived = true; category.HiddInMenu = true; List <Product> MyProductList = new List <Product>(); MyProductList = _ProductManger.GettAll().Where(c => c.CategoryId == category.Id).ToList(); foreach (var item in MyProductList) { item.IsArchived = true; } _ProductManger.Save(); _CategoryManger.Save(); return(RedirectToAction("Index")); }