public ActionResult MdlDelete(long modelId) { SK_MODEL deletedModel = repository.DeleteModel(modelId); if (deletedModel != null) { TempData["message"] = string.Format("{0} был удален", deletedModel.Code); } return(RedirectToAction("Mdls")); }
public SK_MODEL DeleteModel(long modelId) { SK_MODEL dbEntry = context.SK_MODEL.Where(x => x.ModelId == modelId).Single(); if (dbEntry != null) { context.SK_MODEL.Remove(dbEntry); context.SaveChanges(); } return(dbEntry); }
public ViewResult MdlEdit(long modelId) { SK_MODEL mdl = repository.Models.Where(x => x.ModelId == modelId).FirstOrDefault(); IEnumerable <CT_BRAND> brands = repository.Brands; var mdlVM = new MdlViewModel { Mdl = mdl, Brands = brands }; return(View(mdlVM)); }
public void SaveModel(SK_MODEL mdl) { mdl.DateLoad = DateTime.Now; if (mdl.ModelId == 0) { context.SK_MODEL.Add(mdl); } else { SK_MODEL dbEntry = context.SK_MODEL.Where(x => x.ModelId == mdl.ModelId).Single(); if (dbEntry != null) { dbEntry.BrandId = mdl.BrandId; dbEntry.Code = mdl.Code; dbEntry.Name = mdl.Name; dbEntry.CT_BRAND = mdl.CT_BRAND; dbEntry.DateLoad = mdl.DateLoad; } } context.SaveChanges(); }