private void GetValidate(AD_PAGE item, ref string errorMsg) { if (string.IsNullOrEmpty(item.ID)) { errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get( VNPTResources.ID.MsgErrorRequire), VNPTResources.Instance.Get(VNPTResources.ID.Label_page_ID)), ". "); } else { if (!CustomValidation.maxLength(150, item.ID)) { errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get( VNPTResources.ID.MsgErrorMaximumLength), VNPTResources.Instance.Get(VNPTResources.ID.Label_page_ID), 150), ". "); } if (CustomValidation.hasSpace(item.ID)) { errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get( VNPTResources.ID.MsgErrorHasSpace), VNPTResources.Instance.Get(VNPTResources.ID.Label_page_ID)), ". "); } } if (string.IsNullOrEmpty(item.Name)) { errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get( VNPTResources.ID.MsgErrorRequire), VNPTResources.Instance.Get(VNPTResources.ID.Label_page_Nm)), ". "); } else { if (!CustomValidation.maxLength(150, item.Name)) { errorMsg = string.Concat(errorMsg, string.Format(VNPTResources.Instance.Get( VNPTResources.ID.MsgErrorMaximumLength), VNPTResources.Instance.Get(VNPTResources.ID.Label_page_Nm), 150), ". "); } } }
public IHttpActionResult Put(string id, [FromBody] AD_PAGE dataRequest) { try { //validate custom data input string errorMsg = null; GetValidate(dataRequest, ref errorMsg); //validate custom data input if (errorMsg != "" && errorMsg != null) { return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = errorMsg })); } if (!ModelState.IsValid) { var model = ModelState; string msg = VNPTResources.Instance.Get(model); return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = msg })); } var dataItem = this.Repository.GetQuery <AD_PAGE>().FirstOrDefault(r => r.ID == id); if (dataItem is null) { return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = VNPTResources.Instance.Get(VNPTResources.ID.MsgNotFound) })); } dataItem = dataRequest.Clone(); dataItem.ID = id; this.Repository.Update(dataItem); this.VNPTLogs.Write(this.Repository, EAction.Update, JsonConvert.SerializeObject(dataItem)); this.Repository.UnitOfWork.SaveChanges(); return(Json(new TResult() { Status = (short)EStatus.Ok, Msg = string.Format(VNPTResources.Instance.Get(VNPTResources.ID.MsgUpdateDataSuccess), VNPTResources.Instance.Get(VNPTResources.ID.Label_obj_page)), Data = dataItem })); } catch (Exception e) { this.VNPTLogs.Write(this.RepositoryLog, e.Message); return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = e.Message })); } }
public IHttpActionResult Post([FromBody] AD_PAGE dataRequest) { try { //validate custom data input string errorMsg = null; GetValidate(dataRequest, ref errorMsg); //validate custom data input if (errorMsg != "" && errorMsg != null) { return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = errorMsg })); } if (!ModelState.IsValid) { var model = ModelState; string msg = VNPTResources.Instance.Get(model); return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = msg })); } if (this.Repository.GetQuery <AD_PAGE>().Any(r => r.ID.Equals(dataRequest.ID))) { return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = string.Format(VNPTResources.Instance.Get(VNPTResources.ID.MsgErrorIsExists), dataRequest.ID) })); } var dataItem = dataRequest.Clone(); this.Repository.Add(dataItem); this.VNPTLogs.Write(this.Repository, EAction.Insert, JsonConvert.SerializeObject(dataItem)); this.Repository.UnitOfWork.SaveChanges(); return(Json(new TResult() { Status = (short)EStatus.Ok, Msg = string.Format(VNPTResources.Instance.Get(VNPTResources.ID.MsgCreateDataSuccess), VNPTResources.Instance.Get(VNPTResources.ID.Label_obj_page)), Data = dataItem })); } catch (Exception e) { this.VNPTLogs.Write(this.RepositoryLog, e.Message); return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = e.Message })); } }
public IHttpActionResult Saves(IEnumerable <AD_PAGE> dataRequest) { try { if (!ModelState.IsValid) { var model = ModelState; string msg = VNPTResources.Instance.Get(model); return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = msg })); } AD_PAGE dataItem = null; foreach (var item in dataRequest) { string errorMsg = null; GetValidate(item, ref errorMsg); if (!string.IsNullOrEmpty(errorMsg)) { return(Json(new TResult() { Status = (int)EStatus.Fail, Msg = errorMsg })); } dataItem = this.Repository.GetQuery <AD_PAGE>().FirstOrDefault(r => r.ID == item.ID); if (dataItem is null) { dataItem = item.Clone(); this.Repository.Add(dataItem); this.VNPTLogs.Write(this.Repository, EAction.Insert, JsonConvert.SerializeObject(dataItem)); } else { return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = string.Format(VNPTResources.Instance.Get(VNPTResources.ID.MsgErrorIsExists), item.ID) })); } } this.Repository.UnitOfWork.SaveChanges(); return(Json(new TResult() { Status = (short)EStatus.Ok, Msg = string.Format(VNPTResources.Instance.Get(VNPTResources.ID.MsgUpdateDataSuccess), VNPTResources.Instance.Get(VNPTResources.ID.Label_obj_page)), })); } catch (Exception e) { this.VNPTLogs.Write(this.Repository, e.Message); return(Json(new TResult() { Status = (short)EStatus.Fail, Msg = e.Message })); } }
private void SaveRoleControl(IQueryable<AD_CONTROL> controlSQL, List<string> controls, AD_PAGE page, string roleID) { var flag = false; var pageID = page.ID; var rolePageValue = JsonConvert.SerializeObject(controls); if (string.IsNullOrEmpty(page.Value) || !page.Value.Equals(rolePageValue)) { flag = true; page.Value = rolePageValue; this.Repository.Update(page); } var controlDBs = controlSQL.ToList(); foreach (var item in controls) { if (!controlDBs.Any(r => r.ID.Equals(item))) { flag = true; this.Repository.Add(new AD_CONTROL() { ID = item }); } } var rolePage = this.Repository.GetQuery<AD_ROLE_PAGE>().FirstOrDefault(r => r.RoleID.Equals(roleID) && r.PageID.Equals(pageID)); if (rolePage == null) { rolePage = new AD_ROLE_PAGE() { RoleID = roleID, PageID = pageID, Value = rolePageValue, CreateAt = DateTime.Now, UpdateAt = DateTime.Now, ActiveFlg = true }; flag = true; this.Repository.Add(rolePage); } if (flag) this.Repository.UnitOfWork.SaveChanges(); }