Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Edit(RepresentativeUserViewModel representativeUserModel)
        {
            var userId = Convert.ToInt32(User.Identity.Name);

            if (!await _representativeUserService.CanEditEmail(userId, representativeUserModel.Email))
            {
                ModelState.AddModelError("", "پست الکترونیکی وارد شده قبلا توسط فرد دیگری ثبت شده است.");
                return(this.JsonValidationErrors());
            }

            var selectedUser = await _representativeUserService.FindById(userId);

            selectedUser.FirstName    = representativeUserModel.FirstName;
            selectedUser.LastName     = representativeUserModel.LastName;
            selectedUser.MobileNumber = representativeUserModel.MobileNumber;
            selectedUser.NationalCode = representativeUserModel.NationalCode;
            selectedUser.FatherName   = representativeUserModel.FatherName;
            selectedUser.Email        = representativeUserModel.Email;

            await _dbContext.SaveChangesAsync();

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }