public ContractorPresentationStub(contractor dbItem) { this.Id = dbItem.id; this.Name = dbItem.name; this.Deleted = dbItem.deleted; this.ContractorType = dbItem.contractor_type; }
public ActionResult Create(ContractorFormStub model) { //bool isNameExist = RepoContractor.Find().Where(p => p.name == model.Name).Count() > 0; if (ModelState.IsValid) { contractor dbItem = new contractor(); dbItem = model.GetDbObject(dbItem); try { RepoContractor.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 contractor GetDbObject(contractor dbItem) { dbItem.id = this.Id; dbItem.name = this.Name; dbItem.deleted = this.Deleted; dbItem.contractor_type = this.ContractorType; return dbItem; }
public ContractorFormStub(contractor dbItem) : this() { this.Id = dbItem.id; this.Name = dbItem.name; this.Deleted = dbItem.deleted; this.ContractorType = dbItem.contractor_type; }
public void Save(contractor dbItem) { if (dbItem.id == 0) //create { context.contractors.Add(dbItem); } else //edit { var entry = context.Entry(dbItem); entry.State = EntityState.Modified; } context.SaveChanges(); }
public void Delete(contractor dbItem) { context.contractors.Remove(dbItem); context.SaveChanges(); }