private static Locator getEntityByModel(LocatorModel model) { if (model == null) return null; Locator entity = new Locator(); if (model.Id == 0) { entity.CompanyId = AuthenticationHelper.CompanyId.Value; entity.CreateBy = AuthenticationHelper.UserId; entity.CreateDate = DateTime.Now; } else { entity.CompanyId = model.CompanyId; entity.CreateBy = model.CreateBy; entity.CreateDate = model.CreateDate; } entity.Description = model.Description; entity.Id = model.Id; entity.SOBId = model.SOBId; entity.Status = model.Status; entity.UpdateBy = AuthenticationHelper.UserId; entity.UpdateDate = DateTime.Now; return entity; }
public ActionResult Create() { LocatorModel model = SessionHelper.Locator; if (model == null) { model = new LocatorModel { SOBId = SessionHelper.SOBId }; ViewBag.SOBName = SetOfBookHelper.GetSetOfBook(SessionHelper.SOBId.ToString()).Name; SessionHelper.Locator = model; if (SessionHelper.Locator.LocatorWarehouses == null) SessionHelper.Locator.LocatorWarehouses = new List<LocatorWarehouseModel>(); } model.CompanyId = AuthenticationHelper.CompanyId.Value; return View(model); }
public static void Save(LocatorModel locatorModel) { Locator entity = getEntityByModel(locatorModel); string result = string.Empty; if (entity.IsValid()) { if (locatorModel.Id > 0) result = service.Update(entity); else result = service.Insert(entity); if (!string.IsNullOrEmpty(result)) { var savedDetail = GetLocatorWarehouses(result); if (savedDetail.Count() > locatorModel.LocatorWarehouses.Count()) { var tobeDeleted = savedDetail.Take(savedDetail.Count() - locatorModel.LocatorWarehouses.Count()); foreach (var item in tobeDeleted) { service.DeleteLocatorWarehouse(item.Id); } savedDetail = GetLocatorWarehouses(result); } foreach (var detail in locatorModel.LocatorWarehouses) { LocatorWarehouse detailEntity = getEntityByModel(detail, 0); if (detailEntity.IsValid()) { detailEntity.LocatorId = Convert.ToInt64(result); if (savedDetail.Count() > 0) { detailEntity.Id = savedDetail.FirstOrDefault().Id; savedDetail.Remove(savedDetail.FirstOrDefault(rec => rec.Id == detailEntity.Id)); service.Update(detailEntity); } else service.Insert(detailEntity); } } } } }
public static LocatorModel GetLocator(string id) { LocatorModel model = new LocatorModel(service.GetSingle(id, AuthenticationHelper.CompanyId.Value)); return model; }
public ActionResult Save(LocatorModel model) { string message = ""; try { bool saved = false; if (SessionHelper.Locator != null) { SessionHelper.Locator.CompanyId = model.CompanyId; SessionHelper.Locator.Description = string.IsNullOrEmpty(model.Description) ? "" : model.Description; SessionHelper.Locator.Id = model.Id; SessionHelper.Locator.SOBId = SessionHelper.SOBId; SessionHelper.Locator.Status = model.Status; LocatorHelper.Save(SessionHelper.Locator); SessionHelper.Locator = null; saved = true; } else message = "No Locator information available!"; return Json(new { success = saved, message = message }); } catch (Exception e) { message = e.Message; return Json(new { success = false, message = message }); } }