Example #1
0
        public async Task <IHttpActionResult> CreateOneSlideshowEntry(
            [NotNull] CreateOrUpdateOneSlideshowEntryRequestDto dto)
        {
            if (!Helpers.IsTrustedUrl(dto.BackgroundImage))
            {
                return(this.BadRequest(nameof(dto), nameof(dto.BackgroundImage), Errors.Invalid));
            }
            _dbContext.Feeds.Add(new Models.Feed
            {
                StreamName = SlideshowStream.Name,
                Properties = JsonConvert.SerializeObject(new SlideshowStream.FeedProperties
                {
                    Title           = dto.Title,
                    Subtitle        = dto.Subtitle,
                    Author          = dto.Author,
                    Date            = dto.Date,
                    MinorTitle      = dto.MinorTitle,
                    MinorSubtitle   = dto.MinorSubtitle,
                    BackgroundImage = dto.BackgroundImage,
                    Link            = dto.Link
                })
            });
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
        public async Task <IHttpActionResult> UpdateOneSlideshowEntry(int id,
                                                                      [NotNull] CreateOrUpdateOneSlideshowEntryRequestDto dto)
        {
            var feed = await _dbContext.Feeds.FindAsync(id);

            if (feed == null || feed.StreamName != SlideshowStream.Name)
            {
                return(NotFound());
            }

            if (!Helpers.IsTrustedUrl(dto.BackgroundImage))
            {
                return(this.BadRequest(nameof(dto), nameof(dto.BackgroundImage), Errors.Invalid));
            }

            feed.Properties = JsonConvert.SerializeObject(new SlideshowStream.FeedProperties
            {
                Title           = dto.Title,
                Subtitle        = dto.Subtitle,
                Author          = dto.Author,
                Date            = dto.Date,
                MinorTitle      = dto.MinorTitle,
                MinorSubtitle   = dto.MinorSubtitle,
                BackgroundImage = dto.BackgroundImage,
                Link            = dto.Link
            });

            await _dbContext.SaveChangesAsync();

            return(Ok());
        }