Beispiel #1
0
        internal static async void ExecutePostRequests(HttpClient client)
        {
            ResponseAlbumModel testAlbum = new ResponseAlbumModel
            {
                Title        = "Za posleden put fo smeniqm",
                ProducerName = "Common Productions",
                Year         = 2009
            };

            ResponseSongModel song = new ResponseSongModel
            {
                Title    = "EE chovek omruzna mi",
                Genre    = "Bate i na mene spoko",
                Year     = 2015,
                AlbumId  = 4,
                ArtistId = 24
            };

            ResponseArtistModel artist = new ResponseArtistModel
            {
                Name        = "Kaenko Ukolovich",
                Country     = "Ukraine",
                DataOfBirth = new DateTime(1999, 2, 4)
            };

            var httpResponseAlbum = await client.PostAsJsonAsync("api/albums", testAlbum);

            var httpResponseSong = await client.PostAsJsonAsync("api/songs", song);

            var httpResponseArtist = await client.PostAsJsonAsync("api/artists", artist);

            Console.WriteLine(httpResponseAlbum.ReasonPhrase.ToString() + " from albums");
            Console.WriteLine(httpResponseSong.ReasonPhrase.ToString() + " from songs");
            Console.WriteLine(httpResponseArtist.ReasonPhrase.ToString() + " from artists");
        }
        public IHttpActionResult Delete(ResponseArtistModel artist)
        {
            if (this.data.Artists.All().Any(x => x.Id == artist.Id))
            {
                this.data.Artists.Delete(artist.Id);

                int rowsChnaged = this.data.SaveChanges();
                return(this.Ok($"Rows changed ({rowsChnaged})"));
            }

            return(this.BadRequest($"Id of artist not found! Actual: {artist.Id}"));
        }
        public IHttpActionResult Post(ResponseArtistModel artist)
        {
            if (this.ModelState.IsValid)
            {
                Artist artistToAdd = Mapper.Map <Artist>(artist);
                this.data.Artists.Add(artistToAdd);

                int rowsChnaged = this.data.SaveChanges();
                return(this.Ok($"Rows changed ({rowsChnaged})"));
            }

            return(this.BadRequest(this.ModelState));
        }
        public IHttpActionResult Put(ResponseArtistModel artist)
        {
            if (this.ModelState.IsValid)
            {
                Artist artistToUpdate = this.data.Artists.GetById(artist.Id);
                if (artistToUpdate == null)
                {
                    return(this.BadRequest("Artist Not found!"));
                }

                //// Why need this? Because Mapper.Map<T>(obj) returns a new object with the new properties. I can Update
                //// this object - it's not from the database. So I use this Method just to transfer values from properties
                Mapper.DynamicMap(artist, artistToUpdate);
                this.data.Artists.Update(artistToUpdate);

                int rowsChnaged = this.data.SaveChanges();
                return(this.Ok($"Rows changed ({rowsChnaged})"));
            }

            return(this.BadRequest(this.ModelState));
        }
Beispiel #5
0
        internal static void ExecutePutRequests(HttpClient client)
        {
            ResponseAlbumModel updateAlbum = new ResponseAlbumModel
            {
                Id           = 15,
                Title        = "Updated object",
                ProducerName = "Assert.AreEqual(this.StatusCode, StatusCode.Updated)",
                Year         = 2009
            };

            ResponseSongModel updateSong = new ResponseSongModel
            {
                Id       = 32,
                Title    = "Updateed song",
                Genre    = "Genre updated",
                Year     = 2000,
                AlbumId  = 4,
                ArtistId = 25
            };

            ResponseArtistModel updateArtist = new ResponseArtistModel
            {
                Id          = 27,
                Name        = "Updated artist name",
                Country     = "Country Updated",
                DataOfBirth = new DateTime(1999, 2, 4)
            };

            var messages = new List <HttpResponseMessage>
            {
                client.PutAsJsonAsync("api/albums", updateAlbum).Result,
                client.PutAsJsonAsync("api/songs", updateSong).Result,
                client.PutAsJsonAsync("api/artists", updateArtist).Result
            };

            foreach (var msg in messages)
            {
                Console.WriteLine(msg.ReasonPhrase.ToString());
            }
        }
        internal static void ExecutePutRequests(HttpClient client)
        {
            ResponseAlbumModel updateAlbum = new ResponseAlbumModel
            {
                Id = 15,
                Title = "Updated object",
                ProducerName = "Assert.AreEqual(this.StatusCode, StatusCode.Updated)",
                Year = 2009
            };

            ResponseSongModel updateSong = new ResponseSongModel
            {
                Id = 32,
                Title = "Updateed song",
                Genre = "Genre updated",
                Year = 2000,
                AlbumId = 4,
                ArtistId = 25
            };

            ResponseArtistModel updateArtist = new ResponseArtistModel
            {
                Id = 27,
                Name = "Updated artist name",
                Country = "Country Updated",
                DataOfBirth = new DateTime(1999, 2, 4)
            };

            var messages = new List<HttpResponseMessage>
            {
                client.PutAsJsonAsync("api/albums", updateAlbum).Result,
                client.PutAsJsonAsync("api/songs", updateSong).Result,
                client.PutAsJsonAsync("api/artists", updateArtist).Result
            };

            foreach (var msg in messages)
            {
                Console.WriteLine(msg.ReasonPhrase.ToString());
            }
        }
        internal static async void ExecutePostRequests(HttpClient client)
        {
            ResponseAlbumModel testAlbum = new ResponseAlbumModel
            {
                Title = "Za posleden put fo smeniqm",
                ProducerName = "Common Productions",
                Year = 2009
            };

            ResponseSongModel song = new ResponseSongModel
            {
                Title = "EE chovek omruzna mi",
                Genre = "Bate i na mene spoko",
                Year = 2015,
                AlbumId = 4,
                ArtistId = 24
            };

            ResponseArtistModel artist = new ResponseArtistModel
            {
                Name = "Kaenko Ukolovich",
                Country = "Ukraine",
                DataOfBirth = new DateTime(1999, 2, 4)
            };

            var httpResponseAlbum = await client.PostAsJsonAsync("api/albums", testAlbum);
            var httpResponseSong = await client.PostAsJsonAsync("api/songs", song);
            var httpResponseArtist = await client.PostAsJsonAsync("api/artists", artist);

            Console.WriteLine(httpResponseAlbum.ReasonPhrase.ToString() + " from albums");
            Console.WriteLine(httpResponseSong.ReasonPhrase.ToString() + " from songs");
            Console.WriteLine(httpResponseArtist.ReasonPhrase.ToString() + " from artists");
        }