示例#1
0
        // DELETE/POST/UPDATE
        // ======================================================================================================================

        // ADD/POST ANIME WITH OBJECT

        public async Task <AnimeDTO> AddAnime(AnimeDTO anime)
        {
            try
            {
                Anime checkIfExists = await _animeRepository.GetAnimeByName(anime.Name);

                if (checkIfExists != null)
                {
                    return(null);
                }

                Anime newAnime = _mapper.Map <Anime>(anime);
                newAnime.AnimeId = new Guid();
                newAnime.AnimeStreamingServices = new List <AnimeStreamingService>();
                foreach (var streamingServiceId in anime.AnimeStreamingServices)
                {
                    newAnime.AnimeStreamingServices.Add(new AnimeStreamingService()
                    {
                        StreamingServiceId = streamingServiceId
                    });
                }
                await _animeRepository.AddAnime(newAnime);

                return(anime);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        public async Task Post_One_Anime_Should_Return_Ok()
        {
            var anime = new AnimeDTO()
            {
                URLImage = "https://m.media-amazon.com/images/M/MV5BMjUxMzE4ZDctODNjMS00MzIwLThjNDktODkwYjc5YWU0MDc0XkEyXkFqcGdeQXVyNjc3OTE4Nzk@._V1_UY1200_CR85,0,630,1200_AL_.jpg",
                Name     = "Steins Gate",
                Synopsis = "Steins; Gate is a story about time travel and the consequences of it's misuse. The protagonist is a man named Okabe Rintarou; a self-proclaimed 'mad scientist' who goes by the name of Hououin Kyouma. He is about to attend a lecture from a man proclaiming to have discovered the secrets of time travel, Rintarou then challenges his theorem by claiming a man named 'John Titor' has beaten him to it. He is taken away from the lecture by a strange girl named Makise Kurisu who asks him about a previous conversation they had not too long ago, but Rintarou has no idea who this girl is and leaves her- only to find out that shortly after his departure she has been stabbed to death. Perplexed by these recent events, Rintarou sends a message to a friend named Itaru concerning Kurisu's murder. As he clicks the 'send message button' he is unconsciously thrown into a alternate reality several inconsistencies with his own memories such as John Titor never appearing in 2010 or there being a large satellite crashed into the roof of the radio kaikan. Dumbfounded by this experience, he begins to piece together a successful method of time travel. On completion, he begins to misuse this power by helping out friends with past dilemmas, not considering the weight of his actions. Eventually leading to consequences so great, he questions whether or not time travel was worth discovering after all...",
                Rating   = 10,
                StudioId = 18,
                GenreId  = 10,
                AnimeStreamingServices = new List <int>()
                {
                    1, 3, 6, 7
                }
            };

            string json = JsonConvert.SerializeObject(anime);

            var response = await Client.PostAsync("/api/anime",
                                                  new StringContent(json, Encoding.UTF8, "application/json"));

            response.StatusCode.Should().Be(HttpStatusCode.OK);

            var createdAnime = JsonConvert.DeserializeObject <AnimeDTO>(await response.Content.ReadAsStringAsync());

            Assert.NotNull(createdAnime);
            Assert.Equal <string>("Steins Gate", createdAnime.Name);
        }
        public Anime Create(AnimeDTO animeDTO)
        {
            var anime = _unitOfWork.Animes.Create(_mapper.Map <AnimeDTO, Anime>(animeDTO));

            _unitOfWork.Save();

            return(anime);
        }
 public async Task <ActionResult <AnimeDTO> > AddAnime(AnimeDTO anime)
 {
     try{
         return(new OkObjectResult(await _animeService.AddAnime(anime)));
     }
     catch (Exception ex) {
         return(new StatusCodeResult(500));
     }
 }
        public void Update(AnimeDTO animeDTO)
        {
            var anime = GetByKitsuID(animeDTO.KitsuID);

            if (anime == null)
            {
                return;
            }

            _unitOfWork.Animes.Update(_mapper.Map(animeDTO, anime));
            _unitOfWork.Save();
        }
示例#6
0
 private void CreateOrUpdateAnime(AnimeDTO anime)
 {
     if (_animeService.GetByKitsuID(anime.KitsuID) == null)
     {
         _animeService.Create(anime);
         _logger.Emit(ELoggingEvent.AnimeCreated, new { AnimeSlug = anime.Slug });
     }
     else
     {
         _animeService.Update(anime);
         _logger.Emit(ELoggingEvent.AnimeUpdated, new { AnimeSlug = anime.Slug });
     }
 }
示例#7
0
 public Anime(AnimeDTO animeDTO, List <Genre> selectedGenres, List <Studio> selectedStudio)
 {
     Name          = animeDTO.Name;
     ReleaseDate   = animeDTO.ReleaseDate;
     Studio        = animeDTO.Studio;
     Type          = animeDTO.Type;
     CountEpisodes = animeDTO.CountEpisodes;
     Status        = animeDTO.Status;
     Genres        = selectedGenres;
     Source        = animeDTO.Source;
     Season        = animeDTO.Season;
     Voices        = selectedStudio;
     PhotoBase64   = animeDTO.PhotoBase64;
 }
示例#8
0
 public async Task <AnimeDTO> Put(int id, [FromBody] AnimeDTO value)
 {
     return(await animeService.UpdateAnime(id, value));
 }
示例#9
0
 public async Task <AnimeDTO> Post([FromBody] AnimeDTO value)
 {
     return(await animeService.AddAnime(value));
 }