public async Task <bool> UpdateCategories(int id, SeriesCategoryUpdateModel model)
        {
            var pathParams = new HttpPathParameters();

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

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

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

            return(await this.Http.Update <SeriesCategoryUpdateModel>(settings, body));
        }
Exemple #2
0
        /// <summary>
        /// Updates series's categories
        /// </summary>
        /// <param name="id">Series Id</param>
        /// <param name="model">Categories model</param>
        public void UpdateCategories(int id, SeriesCategoryUpdateModel model)
        {
            var user = this.Utils.GetCurrentUser();

            var series = this._databaseContext.Series.Find(id);

            if (series == null)
            {
                return;
            }

            var currentMappings = series.Categories;

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

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

            foreach (int modelId in addList)
            {
                this._databaseContext.SeriesSeriesCategoriesSwitch.Add(new SeriesSeriesCategory
                {
                    CategoryId = modelId, SeriesId = series.Id
                });
            }

            this._databaseContext.SaveChanges();
            this.Logger.LogInformation(user, this.GetService(), this.GetEvent("update"), series.Id);
            this.Notification.AddStatusLibraryNotificationByType(StatusLibraryNotificationType.UpdateSeries, user);
        }
 public IActionResult UpdateCategories(int id, [FromBody] SeriesCategoryUpdateModel model)
 {
     this._seriesService.UpdateCategories(id, model);
     return(this.Ok());
 }