public void Update(PenaltyTypeModel model) { var upt = this._repoPenaltyType.Find(model.id); if (upt.code != model.code) { if (this._repoPenaltyType.Query().FilterCurrentCompany().Filter(x => x.code == model.code).Get().Any()) { throw new Exception(model.code + " is already exists"); } upt.code = model.code; } upt.description = model.description; upt.updatedBy = this.GetCurrentUserId(); upt.updatedDate = DateTime.Now; this._repoPenaltyType.Update(upt); this._unitOfWork.Save(); }
public void Create(PenaltyTypeModel model, out Guid penaltyTypeId) { if (this._repoPenaltyType.Query().Filter(x => x.code == model.code).Get().Any()) { throw new Exception(model.code + " is already exists"); } var currentUserId = this.GetCurrentUserId(); var ins = this._repoPenaltyType .NewEntity(ue => { ue.SetValue(x => x.code, model.code) .SetValue(x => x.description, model.description) .SetCurrentCompany() .SetCurrentUserTo(x => x.updatedBy); }); this._unitOfWork.Save(); penaltyTypeId = ins.id; }
public ActionResult PenaltyTypeCRUD([DataSourceRequest] DataSourceRequest request , UpdateType updateType , PenaltyTypeModel model) { if (model != null && ModelState.IsValid) { try { switch (updateType) { case UpdateType.Create: Guid penaltyTypeId; this._PenaltyTypeService.Create(model, out penaltyTypeId); model.id = penaltyTypeId; break; case UpdateType.Update: this._PenaltyTypeService.Update(model); break; case UpdateType.Destroy: this._PenaltyTypeService.Delete(model.id.Value); break; default: break; } } catch (Exception ex) { this.AddModelError(ex); } } if (model.id.HasValue && updateType != UpdateType.Destroy) { model = this._PenaltyTypeService.GetById(model.id.Value); } return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); }