public ActionResult Create([Bind(Include = "RegisterID,UserID,ProductID,Quantity")] ProductRegister productRegister) { Product product = db.Products.Find(productRegister.ProductID);//product id si ile ürünü bulduk. ekleme işleminden sonra quantity kontrol işlemini yaptıracağız. if (product.ProductQuantity - productRegister.Quantity == 0) { product.ProductStockState = false; // ürün adedi 0 a düştüyse durumu false yap } if (ModelState.IsValid && (product.ProductQuantity - productRegister.Quantity) >= 0) //eğer miktar 0 veya üzeirndeyse işleme izin vermeyecek. { db.ProductRegisters.Add(productRegister); product.ProductQuantity = product.ProductQuantity - productRegister.Quantity; //quantity düşüyor. miktar kontrol edilip uuygunluğu kontrol edilecek. db.Entry(product).State = EntityState.Modified; //değişiklik kaydı. db.SaveChanges(); //save change return(RedirectToAction("Index")); } else { ViewBag.StockState = "Insufficient Stock! Available Stock : " + product.ProductQuantity; } ViewBag.ProductID = new SelectList(db.Products.Where(u => u.ProductStockState == true), "ProductID", "ProductName", productRegister.ProductID); ViewBag.UserID = new SelectList(db.Users.Where(u => u.UserIsActive == true), "UserID", "UserName", productRegister.UserID); return(View(productRegister)); }
public ActionResult Create([Bind(Include = "BrandID,BrandName")] Brand brand) { if (ModelState.IsValid) { db.Brands.Add(brand); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(brand)); }
public ActionResult Create([Bind(Include = "DepartmentID,DepartmentName")] Department department) { if (ModelState.IsValid) { db.Departments.Add(department); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(department)); }
public ActionResult Create([Bind(Include = "ProductTypeID,ProductName")] ProductType productType) { if (ModelState.IsValid) { db.ProductTypes.Add(productType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productType)); }
public ActionResult Create([Bind(Include = "UserID,UserName,UserSurname,RoleID,DepartmentID,UserIsActive,UserPassword")] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.DepartmentID = new SelectList(db.Departments, "DepartmentID", "DepartmentName", user.DepartmentID); ViewBag.RoleID = new SelectList(db.UserRoles, "UserRoleID", "UserRoleName", user.RoleID); return(View(user)); }
public ActionResult Create([Bind(Include = "ProductID,ProductName,ProductTypeID,ProductStockState,BrandID,AcceptDate,ProductPrice,ProductQuantity,UserID")] Product product) { if (product.ProductQuantity == 0) { product.ProductStockState = false; } if (ModelState.IsValid && !(product.ProductQuantity < 0)) { db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BrandID = new SelectList(db.Brands, "BrandID", "BrandName", product.BrandID); ViewBag.ProductTypeID = new SelectList(db.ProductTypes, "ProductTypeID", "ProductName", product.ProductTypeID); ViewBag.UserID = new SelectList(db.Users.Where(u => u.UserIsActive == true), "UserID", "UserName", product.UserID); return(View(product)); }