Exemple #1
0
        public ActionResult AddNewUser(UsersDto usersDto)
        {
            if (usersDto != null)
            {
                var user = usersDto.GetUser(usersDto);
                if (user != null)
                {
                    try
                    {
                        userService.InsertUser(user);
                    }
                    catch (Exception e)
                    {
                        Program.Logger.Error(e);
                        return(Ok(GetResponse(ResponseType.FAIL, ResponseStatusCode.FAIL, GetError(ErrorCodes.dataNotFound, "Failed", "Error occurred while adding new user"))));
                    }

                    return(Ok(GetResponse(ResponseType.ACK, ResponseStatusCode.SUCCESS)));
                }
                else
                {
                    return(Ok(GetResponse(ResponseType.FAIL, ResponseStatusCode.FAIL, GetError(ErrorCodes.dataNotFound, "Failed", "Something went wrong."))));
                }
            }
            else
            {
                return(BadRequest(GetResponse(ResponseType.ERROR, ResponseStatusCode.ERROR, GetError(ErrorCodes.invalidData, "Invalid input", "Please enter proper user details"))));
            }
        }
Exemple #2
0
        public ActionResult UpdateUser(UsersDto usersDto)
        {
            if (usersDto != null)
            {
                try
                {
                    var userFromDb = userService.GetUser(usersDto.Id);
                    if (userFromDb != null)
                    {
                        var convertedUser = usersDto.GetUser(userFromDb, usersDto);
                        userService.UpdateUser(convertedUser);
                    }
                    else
                    {
                        throw new Exception("The user does not exist");
                    }
                }
                catch (Exception e)
                {
                    Program.Logger.Error(e);
                    return(Ok(GetResponse(ResponseType.FAIL, ResponseStatusCode.FAIL, GetError(ErrorCodes.dataNotFound, "Failed", "Error occurred while updating the user"))));
                }

                return(Ok(GetResponse(ResponseType.ACK, ResponseStatusCode.SUCCESS)));
            }
            else
            {
                return(BadRequest(GetResponse(ResponseType.ERROR, ResponseStatusCode.ERROR, GetError(ErrorCodes.invalidData, "Invalid input", "Please enter proper user details"))));
            }
        }