public ActionResult Edit(CarBrandFormStub model) { //bool isNameExist = RepoKompetitor.Find().Where(p => p.name == model.Name && p.id != model.Id).Count() > 0; if (ModelState.IsValid) { car_brand dbItem = RepoCarBrand.FindByPk(model.Id); dbItem = model.GetDbObject(dbItem); try { RepoCarBrand.Save(dbItem); } catch (Exception e) { return(View("Form", model)); } //message string template = HttpContext.GetGlobalResourceObject("MyGlobalMessage", "CreateSuccess").ToString(); this.SetMessage(model.Name, template); return(RedirectToAction("Index")); } else { car_brand car_brand = RepoCarBrand.FindByPk(model.Id); ViewBag.name = car_brand.name; return(View("Form", model)); } }
public ActionResult Edit(System.Guid id) { car_brand car_brand = RepoCarBrand.FindByPk(id); ViewBag.name = car_brand.name; CarBrandFormStub formStub = new CarBrandFormStub(car_brand); return(View("Form", formStub)); }
public void Save(car_brand dbItem) { if (dbItem.id == Guid.Empty) //create { dbItem.id = Guid.NewGuid(); car_brand checkUnique = context.car_brand.Where(x => x.id == dbItem.id).FirstOrDefault(); while (checkUnique != null) { dbItem.id = Guid.NewGuid(); checkUnique = context.car_brand.Where(x => x.id == dbItem.id).FirstOrDefault(); } context.car_brand.Add(dbItem); } else //edit { var entry = context.Entry(dbItem); entry.State = EntityState.Modified; } context.SaveChanges(); }
public ActionResult Create(CarBrandFormStub model) { //bool isNameExist = RepoCarBrand.Find().Where(p => p.name == model.Name).Count() > 0; if (ModelState.IsValid) { car_brand dbItem = new car_brand(); dbItem = model.GetDbObject(dbItem); RepoCarBrand.Save(dbItem); //message string template = HttpContext.GetGlobalResourceObject("MyGlobalMessage", "CreateSuccess").ToString(); this.SetMessage(model.Name, template); return(RedirectToAction("Index")); } else { return(View("Form", model)); } }
public car_brand GetDbObject(car_brand dbItem) { dbItem.id = this.Id; dbItem.name = this.Name; return(dbItem); }
public CarBrandFormStub(car_brand dbItem) : this() { this.Id = dbItem.id; this.Name = dbItem.name; }
public CarBrand(car_brand dbitem) { CarBrandName = dbitem.name; }
public CarBrandPresentationStub(car_brand dbItem) { this.Id = dbItem.id; this.IdCarBrand = dbItem.id; this.Name = dbItem.name; }
public void Delete(car_brand dbItem) { context.car_brand.Remove(dbItem); context.SaveChanges(); }