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)); }
/// <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); }
public IActionResult UpdateCategories(int id, [FromBody] MovieCategoryUpdateModel model) { this._movieService.UpdateCategories(id, model); return(this.Ok()); }