Example #1
0
        public async Task<ActionResult> Edit(UserViewModel userModel)
        {
            if (!await _userService.CanChangeEmail(userModel.Email, userModel.Id))
            {
                ModelState.AddModelError("", "پست الکترنیکی وارد شده قبلا در سیستم ثبت شده است.");
                return this.JsonValidationErrors();
            }

            var user = new DomainClasses.User()
            {
                Id = userModel.Id,
                Email = userModel.Email,
                FirstName = userModel.FirstName,
                LastName = userModel.LastName,
                Role = userModel.Role
            };

            if (!string.IsNullOrEmpty(userModel.Password))
                user.Password = EncryptionHelper.Encrypt(userModel.Password, EncryptionHelper.Key);

            _userService.Edit(user);

            await _dbContext.SaveChangesAsync();

            return new HttpStatusCodeResult(HttpStatusCode.OK);
        }
Example #2
0
        public async Task<ActionResult> Add(UserViewModel userModel)
        {
            if (await _userService.IsEmailExist(userModel.Email))
            {
                ModelState.AddModelError("", "پست الکترنیکی وارد شده قبلا در سیستم ثبت شده است.");
                return this.JsonValidationErrors();
            }

            _userService.Add(new DomainClasses.User()
            {
                Email = userModel.Email,
                FirstName = userModel.FirstName,
                LastName = userModel.LastName,
                Password = EncryptionHelper.Encrypt(userModel.Password, EncryptionHelper.Key),
                Role = userModel.Role
            });

            await _dbContext.SaveChangesAsync();

            return new HttpStatusCodeResult(HttpStatusCode.OK);
        }