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

            var representativeUser = new DomainClasses.RepresentativeUser
            {
                Id           = representativeUserModel.Id,
                Email        = representativeUserModel.Email,
                FirstName    = representativeUserModel.FirstName,
                LastName     = representativeUserModel.LastName,
                FatherName   = representativeUserModel.FatherName,
                MobileNumber = representativeUserModel.MobileNumber,
                NationalCode = representativeUserModel.NationalCode,
                UniversityId = representativeUserModel.UniversityId,
                Password     = EncryptionHelper.Encrypt(
                    !string.IsNullOrEmpty(representativeUserModel.Password)
                        ? representativeUserModel.Password
                        : CreatePassword(6), EncryptionHelper.Key
                    ),
            };


            _representativeUserService.Edit(representativeUser);

            await _dbContext.SaveChangesAsync();

            return(Json(representativeUser.Id));
        }