Esempio n. 1
0
        private object SaveAll()
        {
            var resources = Request.Body.FromJson <List <SeriesResource> >();

            var seriesToUpdate = resources.Select(seriesResource =>
            {
                var series        = _seriesService.GetSeries(seriesResource.Id);
                var updatedSeries = seriesResource.ToModel(series);

                // If the new language profile doens't exist, keep it the same.
                // This could happen if a 3rd-party app uses this endpoint to update a
                // series and doesn't pass the languageProfileI as well.

                if (!_languageProfileService.Exists(updatedSeries.LanguageProfileId))
                {
                    updatedSeries.LanguageProfileId = series.LanguageProfileId;
                }

                return(updatedSeries);
            }).ToList();

            return(ResponseWithCode(_seriesService.UpdateSeries(seriesToUpdate, true)
                                    .ToResource(false)
                                    , HttpStatusCode.Accepted));
        }
Esempio n. 2
0
        protected override bool IsValid(PropertyValidatorContext context)
        {
            if (context.PropertyValue == null)
            {
                return(true);
            }

            return(_profileService.Exists((int)context.PropertyValue));
        }
Esempio n. 3
0
        private int AddSeries(SeriesResource seriesResource)
        {
            var model = seriesResource.ToModel();

            // Set a default LanguageProfileId to maintain backwards compatibility with apps using the v2 API
            if (model.LanguageProfileId == 0 || !_languageProfileService.Exists(model.LanguageProfileId))
            {
                model.LanguageProfileId = _languageProfileService.All().First().Id;
            }

            return(_addSeriesService.AddSeries(model).Id);
        }