public ActionResult Create(CompanyFormStub model) { //bool isNameExist = RepoCompany.Find().Where(p => p.name == model.Name).Count() > 0; if (ModelState.IsValid) { company dbItem = new company(); dbItem = model.GetDbObject(dbItem); try { RepoCompany.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 { return View("Form", model); } }
public void Save(company dbItem) { if (dbItem.id == 0) //create { context.companies.Add(dbItem); } else //edit { var entry = context.Entry(dbItem); entry.State = EntityState.Modified; } context.SaveChanges(); }
public void Delete(company dbItem) { context.companies.Remove(dbItem); context.SaveChanges(); }
public company GetDbObject(company dbItem) { dbItem.id = this.Id; dbItem.name = this.Name; return dbItem; }
public CompanyFormStub(company dbItem) : this() { this.Id = dbItem.id; this.Name = dbItem.name; }
public CompanyPresentationStub(company dbItem) { this.Id = dbItem.id; this.Name = dbItem.name; }