Exemplo n.º 1
0
        public async Task <bool> UpdateCategories(int id, MovieCategoryUpdateModel model)
        {
            var pathParams = new HttpPathParameters();

            pathParams.Add <int>(id, -1);

            var settings = new HttpSettings($"{this.Url}/categories", null, pathParams, "Movie category updating");

            var body = new HttpBody <MovieCategoryUpdateModel>(model);

            return(await this.Http.Update <MovieCategoryUpdateModel>(settings, body));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates movie's categories
        /// </summary>
        /// <param name="id">Movie Id</param>
        /// <param name="model">Categories model</param>
        public void UpdateCategories(int id, MovieCategoryUpdateModel model)
        {
            var user = this.Utils.GetCurrentUser();

            var movie = this._databaseContext.Movies.Find(id);

            if (movie == null)
            {
                return;
            }

            var currentMappings = movie.Categories;

            foreach (var mapping in currentMappings)
            {
                if (!model.Ids.Contains(mapping.Category.Id))
                {
                    this._databaseContext.MovieMovieCategorySwitch.Remove(mapping);
                }
            }

            var addList = model.Ids.Where(x =>
                                          !currentMappings.Select(y => y.Category.Id).Contains(x)).ToList();

            foreach (int modelId in addList)
            {
                this._databaseContext.MovieMovieCategorySwitch.Add(new MovieMovieCategory
                {
                    CategoryId = modelId, MovieId = movie.Id
                });
            }

            this._databaseContext.SaveChanges();
            this.Logger.LogInformation(user, this.GetService(), this.GetEvent("update"), movie.Id);
            this.Notification.AddStatusLibraryNotificationByType(StatusLibraryNotificationType.UpdateMovie, user);
        }
Exemplo n.º 3
0
 public IActionResult UpdateCategories(int id, [FromBody] MovieCategoryUpdateModel model)
 {
     this._movieService.UpdateCategories(id, model);
     return(this.Ok());
 }