Ejemplo n.º 1
0
        public virtual ActionResult EditUser(EditUserModel userModel)
        {
            ModelState.Remove("BirthDay");
            if (!ModelState.IsValid)
                return PartialView(MVC.Admin.Shared.Views._ValidationSummery);

            var editedUser = new User
            {
                Email = userModel.Email,
                Id = userModel.Id,
                IsBaned = userModel.IsBaned,
                UserName = userModel.UserName,
                Role = _roleService.GetRoleByRoleId(userModel.RoleId),
                UserMetaData = new UserMetaData
                {
                    BirthDay = userModel.BirthDay,
                    Description = userModel.Description,
                    FirstName = userModel.FirstName,
                    LastName = userModel.LastName,
                    Major = userModel.Major
                }
            };

            if (!string.IsNullOrEmpty(userModel.Password))
            {
                editedUser.Password = userModel.Password;
                editedUser.LastPasswordChange = DateAndTime.GetDateTime();
            }
            if (userModel.IsBaned)
            {
                editedUser.BanedDate = DateAndTime.GetDateTime();
            }

            EditedUserStatus editingStatus = _userService.EditUser(editedUser);
            string message;
            switch (editingStatus)
            {
                case EditedUserStatus.UpdatingUserSuccessfully:
                    message = "اطلاعات کاربر با موفقیت به روز رسانی شد";
                    if (userModel.AvatarStatus == false)
                    {
                        AvatarImage.RemoveAvatarImage(userModel.UserName);
                    }
                    _uow.SaveChanges();
                    return PartialView(MVC.Admin.Shared.Views._Alert,
                        new Alert { Message = message, Mode = AlertMode.Success }); // user added successfully
                case EditedUserStatus.EmailExist:
                    message = "ایمیل وارد شده تکراری است";
                    break;
                case EditedUserStatus.UserNameExist:
                    message = "نام کاربری تکراری است";
                    break;
                default:
                    message = "نام کاربری یا ایمیل تکراری است";
                    break;
            }
            return PartialView(MVC.Admin.Shared.Views._Alert, new Alert { Mode = AlertMode.Error, Message = message });
        }
Ejemplo n.º 2
0
        public virtual ActionResult EditUser(int userId)
        {
            EditUserModel selectedUser = _userService.GetUserDataForEdit(userId);

            var model = new EditUserModel
            {
                BirthDay = selectedUser.BirthDay,
                Description = selectedUser.Description,
                Email = selectedUser.Email,
                FirstName = selectedUser.FirstName,
                LastName = selectedUser.LastName,
                Major = selectedUser.Major,
                UserName = selectedUser.UserName,
                Id = selectedUser.Id,
                RoleId = selectedUser.RoleId,
                IsBaned = selectedUser.IsBaned
            };

            AvatarImage.BasePath = Url.Content("~/Content/avatars/");
            model.AvatarStatus = (AvatarImage.Exist(selectedUser.UserName));

            ViewBag.Roles = new SelectList(_roleService.GetAllRoles(), "Id", "Description", model.RoleId);

            return PartialView(MVC.Admin.User.Views._EditUser, model);
        }