public void Create(IdentificationDocumentModel model, out Guid identificationDocumentId) { if (this._repoIdentificationDocument.Query().Filter(x => x.code == model.code).Get().Any()) { throw new Exception(model.code + " is already exists"); } var currentUserId = this.GetCurrentUserId(); var ins = this._repoIdentificationDocument.Insert(new sys_IdentificationDocument() { code = model.code, description = model.description, updatedBy = currentUserId, }); this._unitOfWork.Save(); identificationDocumentId = ins.id; }
public void Update(IdentificationDocumentModel model) { var upt = this._repoIdentificationDocument.Find(model.id); if (upt.code != model.code) { if (this._repoIdentificationDocument.Query().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._repoIdentificationDocument.Update(upt); this._unitOfWork.Save(); }
public ActionResult IdentificationDocumentCRUD([DataSourceRequest] DataSourceRequest request , UpdateType updateType , IdentificationDocumentModel model) { if (model != null && ModelState.IsValid) { try { switch (updateType) { case UpdateType.Create: Guid identificationDocumentId; this._identificationDocumentService.Create(model, out identificationDocumentId); model.id = identificationDocumentId; break; case UpdateType.Update: this._identificationDocumentService.Update(model); break; case UpdateType.Destroy: this._identificationDocumentService.Delete(model.id.Value); break; default: break; } } catch (Exception ex) { this.AddModelError(ex); } } if (model.id.HasValue && updateType != UpdateType.Destroy) { model = this._identificationDocumentService.GetById(model.id.Value); } return(Json(new[] { model }.ToDataSourceResult(request, ModelState))); }