Beispiel #1
0
        public ActionResult Create()
        {
            UserSinglePageViewModel model = new UserSinglePageViewModel();

            model.UserViewModel = new UserViewModel();
            model.Success       = true;
            return(View("Edit", model));
        }
Beispiel #2
0
        public ActionResult Edit(UserSinglePageViewModel model)
        {
            if (model.UserViewModel.UserId.Equals(Guid.Empty))
            {
                CreateUserRequest  request  = new CreateUserRequest();
                CreateUserResponse response = new CreateUserResponse();
                request.UserId   = Guid.NewGuid();
                request.Username = model.UserViewModel.Username;
                request.Password = model.UserViewModel.Password;
                request.Email    = model.UserViewModel.Email;
                request.Role     = model.UserViewModel.Role.ToString();

                response = userService.CreateUser(request);
                if (response.Success)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    model.Success      = false;
                    model.ErrorMessage = response.Message;
                    return(View(model));
                }
            }
            else
            {
                UpdateUserRequest  request  = new UpdateUserRequest();
                UpdateUserResponse response = new UpdateUserResponse();
                request.UserId   = model.UserViewModel.UserId;
                request.Username = model.UserViewModel.Username;
                request.Password = model.UserViewModel.Password;
                request.Email    = model.UserViewModel.Email;
                request.Role     = model.UserViewModel.Role.ToString();

                response = userService.UpdateUser(request);
                if (response.Success)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    model.Success      = false;
                    model.ErrorMessage = response.Message;
                    return(View(model));
                }
            }
        }
Beispiel #3
0
        public ActionResult Edit(Guid userId)
        {
            UserSinglePageViewModel model    = new UserSinglePageViewModel();
            FindAllUsersResponse    response = userService.ReadUsers();

            if (response.Success)
            {
                model.UserViewModel = response.Users.
                                      Where(x => x.UserId == userId).
                                      FirstOrDefault().
                                      ConvertToUserViewModel();
                model.Success = true;
            }
            else
            {
                model.Success      = false;
                model.ErrorMessage = response.Message;
            }
            return(View(model));
        }