public ActionResult Create(UserViewModel unitViewModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             User          user   = UserMapper.ToUser(unitViewModel);
             Result <bool> result = _userBusiness.AddUser(user);
             if (result.isSuccess)
             {
                 return(RedirectToAction(nameof(Index)));
             }
             else
             {
                 ModelState.AddModelError(string.Empty, result.errorMessage);
                 return(View());
             }
         }
         else
         {
             return(View(unitViewModel));
         }
     }
     catch (Exception ex)
     {
         return(RedirectToAction("AppError", "Error"));
     }
 }
Ejemplo n.º 2
0
        public void AddUser()
        {
            if (User.Password != VerifyPassword)
            {
                PUMessageBox.ShowDialog("两次密码不一致");
                return;
            }

            if (string.IsNullOrEmpty(User.Account) || string.IsNullOrEmpty(User.UserName) || string.IsNullOrEmpty(User.Password) || string.IsNullOrEmpty(User.MobilePhone))
            {
                PUMessageBox.ShowDialog("内容不能为空");
                return;
            }
            UserBusiness userBusiness = new UserBusiness();

            if (userBusiness.VerifyAccountExists(User.Account))
            {
                PUMessageBox.ShowDialog("账号已存在");
            }
            if (userBusiness.AddUser(User))
            {
                PUMessageBox.ShowDialog("添加用户成功");
                User = new User();
            }
            else
            {
                PUMessageBox.ShowDialog("添加用户失败");
            }
        }
Ejemplo n.º 3
0
        public HttpResponseMessage AddUser(UserRegistrationDto newUser)
        {
            if (validations.IsNullOrEmpty(newUser))
            {
                var       message = string.Format("Some values are missing");
                HttpError err     = new HttpError(message);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, err));
            }

            string identityNumber = newUser.Identity_Number;
            string firstName      = newUser.First_Name;
            string lastName       = newUser.Last_Name;
            string email          = newUser.Email;
            string phone          = newUser.Phone;
            string password       = newUser.Password;

            bool requestSuccessful = userBusiness.AddUser(identityNumber, firstName, lastName, email, phone, password);

            if (requestSuccessful == false)
            {
                var       message = userBusiness.RegistrationValidationMessage(identityNumber, firstName, lastName, email, phone, password);
                HttpError error   = new HttpError(string.Format(message));
                return(Request.CreateResponse(HttpStatusCode.BadRequest, error));
            }
            else
            {
                var success = string.Format("User was registered successfully");
                return(Request.CreateResponse(HttpStatusCode.OK, success));
            }
        }
        public IHttpActionResult PostUser([FromBody] User userToAdd)
        {
            UserBusiness tb = new UserBusiness();

            userToAdd.User_ID = Guid.NewGuid().ToString();
            tb.AddUser(userToAdd);
            return(Ok(userToAdd));
        }
Ejemplo n.º 5
0
 protected void btn_AddUser_Click(object sender, EventArgs e)
 {
     try
     {
         string validateResult = ValidateInput();
         if (!validateResult.Equals("ok"))
         {
             Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "parent.layer.msg('" + validateResult + "不能为空!', 1, -1);", true);
             return;
         }
         string account    = tb_account.Text.Trim();
         string password   = tb_password.Text.Trim();
         string name       = tb_name.Text.Trim();
         int    userTypeId = Convert.ToInt32(ddl_UserType.SelectedValue);
         string IDCardNum  = tb_IDCardNum.Text;
         string Phone      = tb_Phone.Text;
         string addresult  = "0";
         if (UserBusiness.IsExist(account, request_id))//除了request_id之外是否存在
         {
             Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "parent.layer.msg('该登录名已存在!', 1, -1);", true);
             return;
         }
         int createuserid = Convert.ToInt32(uid);
         if (request_id != 0)//修改
         {
             addresult = UserBusiness.UpdateUser(request_id, account, password, name, userTypeId, IDCardNum, Phone, createuserid, DateTime.Now);
             if (addresult == "0")
             {
                 //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "alert('添加失败!')", true);
                 Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "parent.layer.msg('修改失败', 1, -1);", true);
             }
             else
             {
                 Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "parent.layer.msg('修改成功', 2, -1);close();", true);
             }
         }
         else//新增
         {
             addresult = UserBusiness.AddUser(account, password, name, userTypeId, IDCardNum, Phone, createuserid, DateTime.Now);
             if (addresult == "0")
             {
                 //ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "alter", "alert('添加失败!')", true);
                 Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "parent.layer.msg('添加失败', 1, -1);", true);
             }
             else
             {
                 Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "parent.layer.msg('添加成功', 2, -1);close();", true);
             }
         }
     }
     catch (Exception ex)
     {
         Page.ClientScript.RegisterStartupScript(this.GetType(), "alter", "parent.layer.msg(''数据加载失败,请重新再试!', 1, -1);", true);
     }
 }
Ejemplo n.º 6
0
 public async Task <IActionResult> Create([FromBody] User user)
 {
     try
     {
         return(Ok(await _userBusiness.AddUser(user)));
     }
     catch (Exception ex)
     {
         return(StatusCode((int)HttpStatusCode.InternalServerError));
     }
 }
Ejemplo n.º 7
0
 public ActionResult AddUser(UserModel user)
 {
     try
     {
         user.CreateUser = CurrentUser.Id;
         bool success = business.AddUser(user);
         return(Json(new JsonMessage(success)));
     }
     catch
     {
         return(Json(new JsonMessage(false)));
     }
 }
Ejemplo n.º 8
0
        public void AddUserError()
        {
            var config         = TestHelper.InitConfiguration();
            var userRepository = new Mock <IUserRepository>();
            var userBusiness   = new UserBusiness(userRepository.Object, config);
            var testUser       = new User
            {
                Username    = "******",
                Password    = "******",
                Email       = "*****@*****.**",
                AccessLevel = 10,
                Name        = "emailTeste"
            };
            var userCreated = userBusiness.AddUser(testUser).Result;

            Assert.Equal("Erro: Falha ao cadastrar.", userCreated);
        }
Ejemplo n.º 9
0
        public ActionResult SaveUser(User Entity)
        {
            try
            {
                var userBusiness = new UserBusiness();

                Entity.Rol    = 2;
                Entity.Status = false;
                Entity.SingUpContractStatus = true;
                userBusiness.AddUser(Entity);

                return(RedirectToAction("SingupAndSignin", "Account"));
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
        }