Ejemplo n.º 1
0
        public IActionResult AddUser(UserModel userModel)
        {
            try
            {
                if (userModel == null)
                {
                    return(BadRequest("Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(BadRequest(errors));
                }

                byte[]   bytes      = Convert.FromBase64String(userModel.userImage);
                string[] extensions = userModel.userPicture.Split('.');
                string   extension  = extensions[extensions.Length - 1];
                string   fileName   = Guid.NewGuid().ToString();
                string   filePath   = environment.WebRootPath + "/assets/images/users/" + fileName + "." + extension;
                using (FileStream binaryFileStream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite))
                {
                    binaryFileStream.Write(bytes, 0, bytes.Length);
                    userModel.userPicture = fileName + "." + extension;
                }
                userModel.userImage = string.Empty;
                UserModel addedUser = usersRepository.AddUser(userModel);
                return(StatusCode(StatusCodes.Status201Created, addedUser));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, errors));
            }
        }
 public IActionResult UpdateMovie(string id, MovieExtendModel movieModel)
 {
     try
     {
         if (movieModel == null)
         {
             return(BadRequest("Data is null."));
         }
         //if (!ModelState.IsValid)
         //{
         //	Errors errors = ErrorsHelper.GetErrors(ModelState);
         //	return BadRequest(errors);
         //}
         var uid = User.Identity.Name;
         movieModel.userID = uid;
         movieModel.imdbID = id;
         MovieExtendModel updatedMovie = moviesExtendRepository.UpdateMovie(movieModel);
         return(Ok(updatedMovie));
     }
     catch (Exception ex)
     {
         Errors errors = ErrorsHelper.GetErrors(ex);
         return(StatusCode(StatusCodes.Status500InternalServerError, errors));
     }
 }
Ejemplo n.º 3
0
        public IActionResult ReturnUserByNamePassword(LoginModel loginModel)
        {
            try
            {
                if (loginModel == null)
                {
                    return(BadRequest("Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(BadRequest(errors));
                }

                LoginModel checkUser = usersRepository.ReturnUserByNamePassword(loginModel);
                if (checkUser == null)
                {
                    Errors errors = ErrorsHelper.GetErrors("Wrong username or password");
                    return(StatusCode(StatusCodes.Status401Unauthorized, errors));
                }
                return(StatusCode(StatusCodes.Status201Created, checkUser));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, errors));
            }
        }
Ejemplo n.º 4
0
 public IActionResult GetOneUser(string id)
 {
     try
     {
         UserModel oneUser = usersRepository.GetOneUserById(id);
         return(Ok(oneUser));
     }
     catch (Exception ex)
     {
         Errors errors = ErrorsHelper.GetErrors(ex);
         return(StatusCode(StatusCodes.Status500InternalServerError, errors));
     }
 }
Ejemplo n.º 5
0
 public IActionResult GetAllUsers()
 {
     try
     {
         List <UserModel> allUsers = usersRepository.GetAllUsers();
         return(Ok(allUsers));
     }
     catch (Exception ex)
     {
         Errors errors = ErrorsHelper.GetErrors(ex);
         return(StatusCode(StatusCodes.Status500InternalServerError, errors));
     }
 }
Ejemplo n.º 6
0
 public IActionResult DeleteUser(string id)
 {
     try
     {
         int i = usersRepository.DeleteUser(id);
         return(NoContent());
     }
     catch (Exception ex)
     {
         Errors errors = ErrorsHelper.GetErrors(ex);
         return(StatusCode(StatusCodes.Status500InternalServerError, errors));
     }
 }
 public IActionResult GetByTitle(string movieTitle)
 {
     try
     {
         var userID = User.Identity.Name;
         MovieExtendModel oneMovie = moviesExtendRepository.GetByTitle(movieTitle, userID);
         return(Ok(oneMovie));
     }
     catch (Exception ex)
     {
         Errors errors = ErrorsHelper.GetErrors(ex);
         return(StatusCode(StatusCodes.Status500InternalServerError, errors));
     }
 }
 public IActionResult GetByWord(string byWord)
 {
     try
     {
         var userID = User.Identity.Name;
         List <MovieExtendModel> movies = moviesExtendRepository.GetByWord(byWord, userID);
         return(Ok(movies));
     }
     catch (Exception ex)
     {
         Errors errors = ErrorsHelper.GetErrors(ex);
         return(StatusCode(StatusCodes.Status500InternalServerError, errors));
     }
 }
 public IActionResult DeleteMovie(string id)
 {
     try
     {
         var userID = User.Identity.Name;
         int i      = moviesExtendRepository.DeleteMovie(id, userID);
         return(NoContent());
     }
     catch (Exception ex)
     {
         Errors errors = ErrorsHelper.GetErrors(ex);
         return(StatusCode(StatusCodes.Status500InternalServerError, errors));
     }
 }
        public async Task <IActionResult> GetImdbByWord(string movieWord)
        {
            //http://localhost:49270/api/imdbMovies/byWord/matrix/

            var id = User.Identity.Name;

            try
            {
                UserModel         userModel = userRepository.GetOneUserById(id);
                List <MovieModel> movies    = await imdbRepository.GetImdbByWord(userModel.userImdbPass, movieWord, id);

                return(Ok(movies));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, errors));
            }
        }
        public async Task <IActionResult> GetImdbById(string movieId)
        {
            //http://localhost:49270/api/imdbMovies/byId/tt3896198/

            var id = User.Identity.Name;

            try
            {
                UserModel        userModel = userRepository.GetOneUserById(id);
                MovieExtendModel oneMovie  = await imdbRepository.GetImdbById(userModel.userImdbPass, movieId, id);

                return(Ok(oneMovie));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, errors));
            }
        }
Ejemplo n.º 12
0
        public IActionResult UpdateUser(string id, UserModel userModel)
        {
            try
            {
                if (userModel == null)
                {
                    return(BadRequest("Data is null."));
                }
                if (!ModelState.IsValid)
                {
                    Errors errors = ErrorsHelper.GetErrors(ModelState);
                    return(BadRequest(errors));
                }

                userModel.userID = id;
                UserModel updatedUser = usersRepository.UpdateUser(userModel);
                return(Ok(updatedUser));
            }
            catch (Exception ex)
            {
                Errors errors = ErrorsHelper.GetErrors(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, errors));
            }
        }