/// <summary> /// Insert đối tượng vào database /// </summary> /// <param name="menu"></param> /// <returns></returns> public string Insert(AdmRolecontextContract admrolecontext, SqlTransaction tran = null) { DataTable dtResult = null; string query = string.Format(@"INSERT INTO Adm_RoleContext VALUES ({0},{1},{2},{3})", (admrolecontext.Contextid != null? admrolecontext.Contextid.ToString() : "null").ToString(), (admrolecontext.Roleid != null? admrolecontext.Roleid.ToString() : "null").ToString(), (admrolecontext.Permission.Trim() != String.Empty ? admrolecontext.Permission.ToString() : "null").ToString(), (admrolecontext.Ordernum.Trim() != String.Empty ? admrolecontext.Ordernum.ToString() : "null").ToString()); query += " ; select SCOPE_IDENTITY();"; if (tran == null) { dtResult = DataProvider.ExecuteQuery(query); } else { dtResult = DataProvider.ExecuteQueryWithTransaction(query, tran); } if (dtResult != null && dtResult.Rows.Count > 0) { return(dtResult.Rows[0][0].ToString()); } return(""); }
public HttpResponseMessage SaveRole(string roleJson, string contextJson, string rightJson) { AdmRoleContract roleDTO = new AdmRoleContract(); roleDTO = JsonConvert.DeserializeObject <AdmRoleContract>(roleJson); string[] selectedContexts = JsonConvert.DeserializeObject <string[]>(contextJson); string[] rightIds = JsonConvert.DeserializeObject <string[]>(rightJson); string roleId = ""; string errMessage = string.Empty; SqlTransaction tran = DataProvider.beginTrans(); try { businessRule.RegistInstants(roleDTO); if (roleDTO.Id > 0) { roleId = roleDT.Update(roleDTO, tran); } else { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { roleId = roleDT.Insert(roleDTO, tran); } else { return(handleBRFailed(errMessage, tran)); } } deleteContext(roleDTO.Id.ToString(), tran); foreach (string contextId in selectedContexts) { AdmRolecontextContract roleCtxDTO = new AdmRolecontextContract(); roleCtxDTO.Roleid = Converter.ToInt32(roleId); roleCtxDTO.Contextid = Converter.ToInt32(contextId); roleCtxDTO.Permission = "1"; roleCtx.Insert(roleCtxDTO, tran); } deleteRight(roleDTO.Id.ToString(), tran); foreach (string rightId in rightIds) { AdmRolerightContract roleRightDTO = new AdmRolerightContract(); roleRightDTO.Roleid = Converter.ToInt32(roleId); roleRightDTO.Rightid = Converter.ToInt32(rightId); roleRightDT.Insert(roleRightDTO, tran); } DataProvider.CommitTrans(tran); UpdateUserSitemap(roleDTO.Id.ToString()); } catch (Exception e) { DataProvider.RollbackTrans(tran); } finally { tran.Dispose(); } return(Request.CreateResponse <string>(HttpStatusCode.OK, errMessage != string.Empty ? errMessage : roleId)); }
override public void RegistInstants(params object[] instants) { if (instants.Length > 0) { this.admrolecontextContract = (AdmRolecontextContract)(instants[0]); } }
/// <summary> /// Cập nhật thông tin đối tượng /// </summary> /// <param name="menu"></param> /// <param name="tran"></param> /// <returns></returns> public string Update(AdmRolecontextContract admrolecontext, SqlTransaction tran = null) { string query = String.Format("UPDATE " + TableName + @" SET ContextID={0},RoleID={1},Permission={2},OrderNum={3} WHERE ID=" + admrolecontext.Id.ToString(), (admrolecontext.Contextid != null? admrolecontext.Contextid.ToString() : "null").ToString(), (admrolecontext.Roleid != null? admrolecontext.Roleid.ToString() : "null").ToString(), (admrolecontext.Permission.Trim() != String.Empty ? admrolecontext.Permission.ToString() : "null").ToString(), (admrolecontext.Ordernum.Trim() != String.Empty ? admrolecontext.Ordernum.ToString() : "null").ToString()); if (tran == null) { DataProvider.ExecuteNonQuery(query); } else { DataProvider.ExecuteNonQueryWithTransaction(query, tran); } return(admrolecontext.Id.ToString()); }
public HttpResponseMessage Save(string admrolecontextJson) { string errMessage = string.Empty; try { AdmRolecontextContract admrolecontext = JsonConvert.DeserializeObject <AdmRolecontextContract>(admrolecontextJson); businessRule.RegistInstants(admrolecontext); if (admrolecontext.Id == 0) { businessRule.RegistRule("Insert"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(admrolecontext))); } else { return(handleBRFailed(errMessage)); } } else { businessRule.RegistRule("Update"); if (businessRule.CheckRules(out errMessage)) { return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(admrolecontext))); } else { return(handleBRFailed(errMessage)); } } } catch (Exception e) { ExceptionHandler.Log(e); return(Request.CreateResponse <string>(HttpStatusCode.OK, "Có lỗi xảy ra trên chương trình.")); } }
public AdmRolecontextRule ValidateInstant(AdmRolecontextContract dto) { return(this); }