public ActionResult Create(SkoViewModel model) { if (!ModelState.IsValid) { return(View(model)); } using (var db = new SkorModelDB()) { var skor = new SkorModel { SkorId = model.SkorId, Name = model.Name, Model = model.Model, Color = model.Color, Size = model.Size, Price = model.Price, Description = model.Description, CategoryId = model.CategoryId }; db.SkorTable.Add(skor); db.SaveChanges(); return(RedirectToAction("Index", "Skor", new { id = model.CategoryId })); } }
public ActionResult Edit(SkoViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Index", new { id = model.CategoryId })); } using (var db = new SkorModelDB()) { var product = db.SkorTable.FirstOrDefault(x => x.CategoryId == model.CategoryId); product.SkorId = model.SkorId; product.Name = model.Name; product.Model = model.Model; product.Color = model.Color; product.Size = model.Size; product.Price = model.Price; product.Description = model.Description; product.CategoryId = model.CategoryId; db.SaveChanges(); return(RedirectToAction("Index", new { id = product.CategoryId })); } }
public ActionResult Create(int?id) { var model = new SkoViewModel { CategoryId = (int)id }; using (var db = new SkorModelDB()) { model.CategoryName = string.Join("", db.CategoriesTable.Where(x => x.CategoryId == id).Select(x => x.CategoryName)); model.CategoryId = (int)id; } return(View(model)); }
public List <SelectListItem> DropDownCategories() { var model = new SkoViewModel(); model.CategoryDropDownList = new List <SelectListItem>(); using (var db = new SkorModelDB()) { foreach (var category in db.CategoriesTable) { model.CategoryDropDownList.Add(new SelectListItem { Value = category.CategoryId.ToString(), Text = category.CategoryName }); } return(model.CategoryDropDownList); } }
public ActionResult ViewSkor(int id, string sort) { var model = new SkoViewModel(); using (var db = new SkorModelDB()) { var sko = db.SkorTable.Find(id); model.CategoryId = sko.CategoryId; model.CategoryName = sko.Category.CategoryName; model.Name = sko.Name; model.Model = sko.Model; model.Color = sko.Color; model.Size = sko.Size; model.Price = sko.Price; model.Description = sko.Description; return(View(model)); } }
public ActionResult Delete(int?id) { using (var db = new SkorModelDB()) { var prod = db.SkorTable.Find(id); var model = new SkoViewModel { SkorId = prod.SkorId, Name = prod.Name, Model = prod.Model, Color = prod.Color, Size = prod.Size, Price = prod.Price, Description = prod.Description }; return(View(model)); } }
public ActionResult Edit(int?id) { using (var db = new SkorModelDB()) { var product = db.SkorTable.Find(id); var model = new SkoViewModel { CategoryName = product.Category.CategoryName, CategoryId = product.CategoryId, SkorId = product.SkorId, Name = product.Name, Model = product.Model, Color = product.Color, Size = product.Size, Price = product.Price, Description = product.Description, CategoryDropDownList = DropDownCategories() }; return(View(model)); } }