public static string Save(VendorModel model) { Vendor entity = GetEntityByModel(model); return model.Id > 0 ? service.Update(entity) : service.Insert(entity); }
public ActionResult Edit(VendorModel model) { if (ModelState.IsValid) { VendorHelper.Save(model); return RedirectToAction("Index"); } return View(model); }
private static Vendor GetEntityByModel(VendorModel model) { if (model == null) return null; Vendor entity = new Vendor(); entity.Id = model.Id; entity.Name = model.Name; entity.Address = model.Address; entity.ContactNo = model.ContactNo; entity.SOBId = SessionHelper.SOBId; entity.StartDate = model.StartDate; entity.EndDate = model.EndDate; if (model.Id == 0) { entity.CreateBy = AuthenticationHelper.UserId; entity.CreateDate = DateTime.Now; entity.CompanyId = AuthenticationHelper.CompanyId.Value; } else { entity.CreateBy = model.CreateBy; entity.CreateDate = model.CreateDate; entity.CompanyId = model.CompanyId; } entity.UpdateBy = AuthenticationHelper.UserId; entity.UpdateDate = DateTime.Now; return entity; }