// GET: User/Edit/5
        public async Task <ActionResult> Edit(string id)
        {
            UserEditVm model = new UserEditVm();

            model.ApplicationRoles = _role.Roles.Select(r => new SelectListItem
            {
                Text  = r.Name,
                Value = r.Id
            }).ToList();

            if (!String.IsNullOrEmpty(id))
            {
                var user = await _userManager.FindByIdAsync(id);

                if (user != null)
                {
                    model.Id                = user.Id;
                    model.Name              = user.Name;
                    model.PhoneNumber       = user.PhoneNumber;
                    model.Address           = user.Address;
                    model.City              = user.City;
                    model.Zip               = user.Zip;
                    model.State             = user.State;
                    model.Email             = user.Email;
                    model.ApplicationRoleId = _role.Roles.Single(r => r.Name == _userManager.GetRolesAsync(user).Result.Single()).Id;
                }
            }

            return(View(model));
        }
 private UserEditVm PopulateUserInformation(UserEditVm currentUser, User user)
 {
     currentUser.FirstName  = _encript.DencryptData(user.Name);
     currentUser.SecondName = _encript.DencryptData(user.SecondName);
     currentUser.City       = _encript.DencryptData(user.City);
     currentUser.Adress     = _encript.DencryptData(user.Adress);
     currentUser.Telephone  = _encript.DencryptData(user.Telephone);
     currentUser.Image      = user.Image;
     return(currentUser);
 }
        public async Task <IActionResult> Edit(string id, UserEditVm userEditVm)
        {
            if (id != userEditVm.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByIdAsync(userEditVm.Id);

                if (user == null)
                {
                    return(NotFound());
                }

                if (!string.IsNullOrWhiteSpace(userEditVm.Password))
                {
                    var removePassResult = await _userManager.RemovePasswordAsync(user);

                    if (!removePassResult.Succeeded)
                    {
                        foreach (var error in removePassResult.Errors)
                        {
                            ModelState.AddModelError("", error.Description);
                        }

                        return(View(userEditVm));
                    }

                    user.PasswordHash = _passwordHasher.HashPassword(user, userEditVm.Password);
                }

                user.UserName = userEditVm.UserName;

                var result = await _userManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    return(Redirect("/Panel"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }

                return(View(userEditVm));
            }

            return(View(userEditVm));
        }
        public async Task <ActionResult> Edit(string id, UserEditVm model)
        {
            if (ModelState.IsValid)
            {
                User user = await _userManager.FindByIdAsync(id);

                if (user != null)
                {
                    user.Name = model.Name;

                    user.PhoneNumber = model.PhoneNumber;
                    user.City        = model.City;
                    user.State       = model.State;
                    user.Address     = model.Address;
                    user.Zip         = model.Zip;

                    string         existingRole   = _userManager.GetRolesAsync(user).Result.Single();
                    string         existingRoleId = _role.Roles.Single(r => r.Name == existingRole).Id;
                    IdentityResult result         = await _userManager.UpdateAsync(user);

                    if (result.Succeeded)
                    {
                        if (existingRoleId != model.ApplicationRoleId)
                        {
                            IdentityResult roleResult = await _userManager.RemoveFromRoleAsync(user, existingRole);

                            if (roleResult.Succeeded)
                            {
                                UserRole applicationRole = await _role.FindByIdAsync(model.ApplicationRoleId);

                                if (applicationRole != null)
                                {
                                    IdentityResult newRoleResult = await _userManager.AddToRoleAsync(user, applicationRole.Name);

                                    if (newRoleResult.Succeeded)
                                    {
                                        return(RedirectToAction("Index"));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(RedirectToAction("Index"));
        }
        public IActionResult ChangeDetails()
        {
            UserEditVm model  = new UserEditVm();
            User       entity = new User();

            entity           = _servise.GetByID(id);
            model.FirstName  = _encript.DencryptData(entity.Name);
            model.SecondName = _encript.DencryptData(entity.SecondName);
            model.City       = _encript.DencryptData(entity.City);
            model.Adress     = _encript.DencryptData(entity.Adress);
            model.Telephone  = _encript.DencryptData(entity.Telephone);
            UserID           = entity.ID;
            model.Image      = entity.Image;
            loginID          = entity.LoginID;

            return(View(model));
        }
        public IActionResult ChangeDetails(UserEditVm model, IFormFile[] photo)
        {
            User entity = new User();

            entity.ID         = UserID;
            entity.Name       = _encript.EncryptData(model.FirstName);
            entity.SecondName = _encript.EncryptData(model.SecondName);
            entity.City       = _encript.EncryptData(model.City);
            entity.Adress     = _encript.EncryptData(model.Adress);
            entity.Telephone  = _encript.EncryptData(model.Telephone);
            entity.Image      = GetImagePath(photo);
            entity.LoginID    = loginID;
            Addimage(photo);

            _servise.Save(entity);

            return(RedirectToAction("Details"));
        }
示例#7
0
        public IActionResult Profile(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            if (HttpContext.Session.GetString("LoginName") == null)
            {
                ViewBag.checkLogin = 0;
                return(View("AddCart"));
            }

            var user = _serviceCustomer.GetUser(id.Value);

            if (user == null)
            {
                return(NotFound());
            }

            UserEditVm UserEdit = new UserEditVm()
            {
                ID           = user.ID,      // hidden
                ExistAvtPath = user.AvtPath, // hidden
                Password     = user.Password,
                Address      = user.Address,
                Birth        = user.Birth,
                FirstName    = user.FirstName,
                LastName     = user.LastName,
                Level        = user.Level,
                Mail         = user.Mail,
                Note         = user.Note,
                Phone        = user.Phone,
                Status       = user.Status
            };
            var x = _userService.GetList();

            ViewBag.StatusList = x.StatusList;
            return(View(UserEdit));
        }
        public async Task <IActionResult> Edit(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var user = await _userManager.FindByIdAsync(id);

            if (user == null)
            {
                return(NotFound());
            }

            var userEditVm = new UserEditVm()
            {
                Id       = user.Id,
                UserName = user.UserName
            };

            return(View(userEditVm));
        }
 public ActionResult Delete(int id, UserEditVm model)
 {
     return(View());
 }
示例#10
0
        public IActionResult Edit(UserEditVm model)
        {
            if (HttpContext.Session.GetInt32("LoginLevel") != 2)
            {
                ViewBag.checkLogin = 0;
                return(View("../Home/AddCart"));
            }
            if (!ModelState.IsValid)
            {
                var x = _userService.GetList();
                ViewBag.StatusList = x.StatusList;
                return(View(model));
            }

            var users      = _service.GetAll();
            int ErrorCount = 0;

            foreach (UserDto item in users)
            {
                if (item.Phone == model.Phone && item.ID != model.ID)
                {
                    ViewBag.UserPhoneEditErrorMessage = "Error";
                    ErrorCount++;
                }
            }
            var age = _userService.GetAge(model.Birth);

            if (age < 13)
            {
                ViewBag.AgeErrorMessage = "Error!";
                ErrorCount++;
            }
            if (ErrorCount > 0)
            {
                var x = _userService.GetList();
                ViewBag.StatusList = x.StatusList;
                return(View(model));
            }

            UserDto     userDto     = _service.GetUser(model.ID);
            SaveUserDto saveUserDto = _mapper.Map <UserDto, SaveUserDto>(userDto);

            saveUserDto.LastName  = model.LastName;
            saveUserDto.FirstName = model.FirstName;
            saveUserDto.Address   = model.Address;
            saveUserDto.Birth     = model.Birth;
            saveUserDto.Level     = model.Level;
            saveUserDto.Mail      = model.Mail;
            saveUserDto.Note      = model.Note;
            //saveUserDto.Password = model.Password;
            saveUserDto.Phone  = model.Phone;
            saveUserDto.Status = model.Status;

            if (model.Avt != null)
            {
                if (model.ExistAvtPath != null)
                {
                    string filePath = Path.Combine(_hostingEnvironment.WebRootPath, "images", model.ExistAvtPath);
                    System.IO.File.Delete(filePath);
                }
                saveUserDto.AvtPath = ProcessUploadedFile(model);
            }
            _service.Update(saveUserDto);
            return(RedirectToAction("Detail", _service.GetUser(saveUserDto.ID)));
        }