コード例 #1
0
        public ActionResult AddOrUpdateUser(AccountModel model)
        {
            string username = ((AccountModel)Session["user"]).userName;

            try
            {
                IAccountService accountService = new AccountService();
                string          linkApi        = "account/addorupdateuser";
                int             res            = accountService.AddOrUpdateUser(baseAddress, linkApi, model);
                if (res > 0)
                {
                    if (model.id == 0)
                    {
                        model.mgs = "Thêm mới thành công!";
                        log.Info("Thêm mới User thành công");
                    }
                    else
                    {
                        model.mgs = "Cập nhật User thành công!";
                        log.Info("Cập nhật User thành công!");
                    }
                    return(Json(model));
                }
                else
                {
                    if (model.id == 0)
                    {
                        model.mgs = "Không thêm được :(";
                    }
                    else
                    {
                        model.mgs = "Không sửa được :(";
                    }
                    return(Json(model));
                }
            }
            catch (Exception ex)
            {
                log.Error("User:"******"-> " + ex.Message);
                AccountModel modelRes = new AccountModel();
                modelRes.mgs = "-1";
                return(Json(modelRes));
            }
        }
コード例 #2
0
 public ActionResult CreateAccount(AccountModel model)
 {
     try
     {
         IAccountService accountService = new AccountService();
         string          linkApi        = "account/addorupdateuser";
         int             res            = accountService.AddOrUpdateUser(baseAddress, linkApi, model);
         if (res > 0)
         {
             if (model.id == 0)
             {
                 model.mgs = "Thêm mới thành công!";
             }
             else
             {
                 model.mgs = "Cập nhật thành công!";
             }
             return(Json(model));
         }
         else
         {
             if (model.id == 0)
             {
                 model.mgs = "Không thêm được :(";
             }
             else
             {
                 model.mgs = "Không sửa được :(";
             }
             return(Json(model));
         }
     }
     catch (Exception ex)
     {
         log.Error(ex.Message);
         AccountModel modelRes = new AccountModel();
         modelRes.mgs = "-1";
         return(Json(modelRes));
     }
 }