Ejemplo n.º 1
0
        public ActionResult Edit(int id, ShowUserDto dto)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Roles = _getRoles.Execute(new GeneralSearchQuery());
                return(View(dto));
            }

            try
            {
                _editUser.Execute(dto);
                return(RedirectToAction(nameof(Index)));
            }
            catch (NotFoundException)
            {
                return(RedirectToAction(nameof(Index)));
            }
            catch (EntityAlreadyExistsException)
            {
                TempData["error"] = "User with the same username already exists.";
                return(View(dto));
            }
            catch (Exception)
            {
                TempData["error"] = "Something went wrong. Please try again.";
                return(View(dto));
            }
        }
Ejemplo n.º 2
0
 public ActionResult <IEnumerable <UserDTO> > Put([FromBody] UserDTO dto)
 {
     try
     {
         _editUserCommand.Execute(dto);
         return(NoContent());
     }
     catch (Exception)
     {
         return(StatusCode(500, "An error has occured !!"));
     }
 }
Ejemplo n.º 3
0
 public ActionResult Put(int id, [FromBody] CreateUserDto dto)
 {
     dto.Id = id;
     try
     {
         _userEdit.Execute(dto);
         return(StatusCode(204));
     }
     catch (EntityAlreadyExistsException e) { return(UnprocessableEntity(e.Message)); }
     catch (EntityNotFoundException e) { return(NotFound(e.Message)); }
     catch (Exception e) { return(StatusCode(500, e.Message)); }
 }
Ejemplo n.º 4
0
 public IActionResult Put(int id, [FromBody] GetUserDto dto)
 {
     try
     {
         dto.Id = id;
         _editUserCommand.Execute(dto);
         return(StatusCode(204, "Successfully updated user."));
     }
     catch
     {
         return(StatusCode(422, "Error while trying to update user."));
     }
 }
Ejemplo n.º 5
0
        public ActionResult Edit(int id, [FromForm] CreateUserDto dto)
        {
            dto.Id = id;

            try
            {
                // TODO: Add update logic here
                _editUser.Execute(dto);

                return(RedirectToAction(nameof(Index)));
            }
            catch (EntityAlreadyExistsException e) { TempData["Error"] = e.Message; }
            catch (EntityNotFoundException e) { TempData["Error"] = e.Message; }
            catch (Exception e) { TempData["Error"] = "Server error " + e.Message; }
            return(View());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Edit([FromForm] UserEdit userEdit)
        {
            try
            {
                await _signInManager.SignOutAsync();

                var user = await _userManager.GetUserAsync(User);

                userEdit.Id        = user.Id;
                userEdit.ImagePath = await _imageUpload.uploadImage(userEdit.Image);

                await _editUser.Execute(userEdit);

                TempData["msg"] = "Succesfully edited user";
                var editedUser = await _getOneUser.Execute(user.Id);

                var profileUpdate = await _getUserByUsername.Execute(editedUser.Username);

                await _chatHub.SendProfile(profileUpdate);

                var userJedi = await _userManager.FindByNameAsync(profileUpdate.Username);

                await _signInManager.SignInAsync(userJedi, false);

                return(RedirectToAction("Index"));
            }
            catch (EntityAlreadyExistException e)
            {
                TempData["msg"] = e.Message;
                return(RedirectToAction("Edit"));
            }
            catch (ImageExtensionNotAllowedException e)
            {
                TempData["msg"] = e.Message;
                return(RedirectToAction("Edit"));
            }
            catch (ImageFileSizeNotAllowedException e)
            {
                TempData["msg"] = e.Message;
                return(RedirectToAction("Edit"));
            }
            catch (Exception e)
            {
                TempData["msg"] = e.Message;
                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 7
0
 public IActionResult Put(int id, [FromBody] CreateUserDto user)
 {
     try
     {
         user.UserId = id;
         _editUserCommand.Execute(user);
         return(Ok());
     }
     catch (EntityAlreadyExistsException e)
     {
         return(NotFound(e.Message));
     }
     catch (Exception e)
     {
         return(UnprocessableEntity(e.Message));
     }
 }
Ejemplo n.º 8
0
 public IActionResult Put(int id, [FromBody] ShowUserDto dto)
 {
     try
     {
         dto.Id = id;
         _editUser.Execute(dto);
         return(StatusCode(204));
     }
     catch (NotFoundException)
     {
         return(NotFound());
     }
     catch (EntityAlreadyExistsException)
     {
         return(StatusCode(422));
     }
 }
Ejemplo n.º 9
0
 public ActionResult Put(int id, [FromBody] UserSearchDTO value)
 {
     try
     {
         _editUserCommand.Execute(value);
         return(NoContent());
     }catch (AlredyExistException)
     {
         return(StatusCode(422, "Email or Name or Surname or Rolle or Password alredy exist"));
     }
     catch (NotFoundException)
     {
         return(NotFound());
     }
     catch (Exception)
     {
         return(StatusCode(500, "Server error, try later"));
     }
 }
Ejemplo n.º 10
0
        public ActionResult Edit(int id, NapraviKorisnika korisnik)
        {
            if (!ModelState.IsValid)
            {
                TempData["greska"] = "Doslo je do greske pri unosu";
                RedirectToAction("Edit");
            }
            try
            {
                korisnik.KorisnikId = id;
                _editUserCommand.Execute(korisnik);

                return(RedirectToAction(nameof(Index)));
            }
            catch (EntityNotFoundException ex)
            {
                TempData["error"] = ex.Message;
                return(View());
            }
        }
Ejemplo n.º 11
0
 public ActionResult Put(int id, [FromBody]  UserDto dto)
 {
     dto.Id = id;
     try
     {
         _editCommand.Execute(dto);
         return(NoContent());
     }
     catch (EntityNotFoundException e)
     {
         return(NotFound(e.Message));
     }
     catch (EntityAlreadyExistsException e)
     {
         return(Conflict(e.Message));
     }
     catch (Exception)
     {
         return(StatusCode(500, "Server error has occurred."));
     }
 }
Ejemplo n.º 12
0
        public IActionResult Put(int id, [FromForm] EditUserDTO dto)
        {
            try
            {
                var user = baza.Users.Find(id);
                if (user == null)
                {
                    return(NotFound());
                }

                editUser.Execute(dto);
                return(NoContent());
            }
            catch (EntityNotFoundException e)
            {
                return(UnprocessableEntity(e.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
Ejemplo n.º 13
0
        public ActionResult Edit(int id, UserDTO dto)
        {
            if (!ModelState.IsValid)
            {
                return(View(dto));
            }

            try
            {
                _editUser.Execute(dto);
                return(RedirectToAction(nameof(Index)));
            }
            catch (EntityExistException)
            {
                TempData["error"] = "User with same username already exist!";
            }
            catch (EntityNotFoundException)
            {
                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
Ejemplo n.º 14
0
 public IActionResult Put(int id, [FromBody] ShowUserDto dto)
 {
     try
     {
         dto.Id = id;
         editUser.Execute(dto);
         return(StatusCode(204));
     }
     catch (EntityAlreadyExistsException e)
     {
         return(StatusCode(409, new
         {
             Errors = new List <string> {
                 e.Message
             }
         }));
     }
     catch (EntityNotFoundException e)
     {
         return(NotFound(new
         {
             Errors = new List <string> {
                 e.Message
             }
         }));
     }
     catch (Exception e)
     {
         return(StatusCode(500, new
         {
             Errors = new List <string> {
                 e.Message
             }
         }));
     }
 }
Ejemplo n.º 15
0
 public ActionResult Put(int id, [FromBody] UserDTO request)
 {
     try
     {
         _editUserCommand.Execute(request);
         return(NoContent());
     }
     catch (DataNotFoundException)
     {
         return(NotFound("User with that id does not exists"));
     }
     catch (DataAlreadyExistsException)
     {
         return(Conflict("User with that email already exists"));
     }
     catch (DataNotAlteredException)
     {
         return(Conflict("User already have same value for email"));
     }
     catch (Exception)
     {
         return(StatusCode(500, "Server is currently under construction, please try later"));
     }
 }