Exemple #1
0
        public async Task <ActionResult> Put(int id, [FromBody] MangaInputModel input)
        {
            var genre = await this.genreService.Find(input.Genre);

            var publisher = await this.mangaPublisherService.Find(input.Publisher);

            var manga = await this.mangaService.Find(id);

            if (genre == null ||
                publisher == null ||
                manga == null)
            {
                return(BadRequest());
            }
            manga.Genre     = genre;
            manga.Publisher = publisher;
            manga.Title     = string.IsNullOrWhiteSpace(input.Title)
                            ? manga.Title : input.Title;
            manga.Author = string.IsNullOrWhiteSpace(input.Author)
                            ? manga.Author : input.Author;
            manga.Description = string.IsNullOrWhiteSpace(input.Description)
                            ? manga.Description : input.Description;
            manga.Status       = input.Status;
            manga.StartDate    = input.StartDate;
            manga.CompleteDate = input.CompleteDate;

            await this.mangaService.Save(manga);

            await this.publisher.Publish(new MangaUpdatedMessage()
            {
                MangaId = manga.Id, Publisher = manga.Publisher.Name
            });

            return(Ok());
        }
Exemple #2
0
        public async Task <ActionResult> Post([FromBody] MangaInputModel input)
        {
            var genre = await this.genreService.Find(input.Genre);

            var publisher = await this.mangaPublisherService.Find(input.Publisher);

            if (genre == null || publisher == null)
            {
                return(BadRequest());
            }

            var manga = new Manga
            {
                Genre        = genre,
                Publisher    = publisher,
                Title        = input.Title,
                Author       = input.Author,
                Description  = input.Description,
                CompleteDate = input.CompleteDate,
                StartDate    = input.StartDate,
                Status       = input.Status
            };

            await this.mangaService.Save(manga);

            var mangaMessage = new MangaCreatedMessage
            {
                MangaId   = manga.Id,
                Publisher = manga.Publisher.Name
            };


            await this.publisher.Publish(mangaMessage);

            return(Ok());
        }