Esempio n. 1
0
        public HttpResponseMessage Save(string userJson, string roleIds)
        {
            string          userId     = "";
            string          errMessage = "";
            AdmUserContract userDTO    = JsonConvert.DeserializeObject <AdmUserContract>(userJson);

            string[]       selectedRoles = JsonConvert.DeserializeObject <string[]>(roleIds);
            SqlTransaction tran          = DataProvider.beginTrans();

            try
            {
                businessRule.RegistInstants(userDTO);
                userDTO.Sitemap = buildSiteMap(selectedRoles);
                if (userDTO.Id > 0)
                {
                    userId = userDT.Update(userDTO, tran);
                }
                else
                {
                    businessRule.RegistRule("Insert");
                    if (businessRule.CheckRules(out errMessage))
                    {
                        userId = userDT.Insert(userDTO);
                    }
                    else
                    {
                        return(handleBRFailed(errMessage, tran));
                    }
                }
                if (Converter.ToInt32(userId) > 0)
                {
                    deleteOldRoles(userId, tran);
                    foreach (string roleId in selectedRoles)
                    {
                        AdmUserroleContract userRoleDTO = new AdmUserroleContract()
                        {
                            Userid = Converter.ToInt32(userId), Roleid = Converter.ToInt32(roleId)
                        };
                        userRoleDT.Insert(userRoleDTO, tran);
                    }
                }
                DataProvider.CommitTrans(tran);
            }
            catch (Exception e)
            {
                DataProvider.RollbackTrans(tran);
                ExceptionHandler.Log(e);
            }
            return(Request.CreateResponse <string>(HttpStatusCode.OK, errMessage != string.Empty ? errMessage : userId));
        }
Esempio n. 2
0
        public HttpResponseMessage Save(string admuserroleJson)
        {
            string errMessage = string.Empty;

            try
            { AdmUserroleContract admuserrole = JsonConvert.DeserializeObject <AdmUserroleContract>(admuserroleJson);
              businessRule.RegistInstants(admuserrole);
              if (admuserrole.Id == 0)
              {
                  businessRule.RegistRule("Insert");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Insert(admuserrole)));
                  }
                  else
                  {
                      return(handleBRFailed(errMessage));
                  }
              }
              else
              {
                  businessRule.RegistRule("Update");
                  if (businessRule.CheckRules(out errMessage))
                  {
                      return(Request.CreateResponse <string>(HttpStatusCode.OK, dta.Update(admuserrole)));
                  }
                  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."));
            }
        }