Exemplo n.º 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");
        }
Exemplo n.º 2
0
        public IHttpActionResult Delete([FromBody] ResponseSongModel song)
        {
            if (this.data.Songs.All().Any(s => s.Id == s.Id))
            {
                this.data.Songs.Delete(song.Id);

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

            return(this.BadRequest("Id does not exits!"));
        }
Exemplo n.º 3
0
        internal static async void ExecuteDeleteRequests(HttpClient client)
        {
            ResponseSongModel deleteSong = new ResponseSongModel
            {
                Id = 32
            };

            string songToDelete = JsonConvert.SerializeObject(deleteSong);

            var requeset = new HttpRequestMessage(HttpMethod.Delete, "api/songs");
            requeset.Content = new StringContent(songToDelete, Encoding.Unicode, "application/json");

            var response = await client.SendAsync(requeset, HttpCompletionOption.ResponseContentRead);

            Console.WriteLine(response.ReasonPhrase);
            //// DO i need to make same operation for other objects. It's same;
        }
Exemplo n.º 4
0
        internal static async void ExecuteDeleteRequests(HttpClient client)
        {
            ResponseSongModel deleteSong = new ResponseSongModel
            {
                Id = 32
            };

            string songToDelete = JsonConvert.SerializeObject(deleteSong);

            var requeset = new HttpRequestMessage(HttpMethod.Delete, "api/songs");

            requeset.Content = new StringContent(songToDelete, Encoding.Unicode, "application/json");

            var response = await client.SendAsync(requeset, HttpCompletionOption.ResponseContentRead);

            Console.WriteLine(response.ReasonPhrase);
            //// DO i need to make same operation for other objects. It's same;
        }
Exemplo n.º 5
0
        public IHttpActionResult Post(ResponseSongModel song)
        {
            if (this.ModelState.IsValid)
            {
                Artist artitst = this.data.Artists.GetById(song.ArtistId);
                Album  album   = this.data.Albums.GetById(song.AlbumId);

                if (album != null && artitst != null)
                {
                    this.data.Songs.Add(Mapper.Map <Song>(song));
                    int rowsChanged = this.data.SaveChanges();

                    return(this.Ok($"Rows affected ({rowsChanged})"));
                }
            }

            return(this.BadRequest(this.ModelState));
        }
Exemplo n.º 6
0
        public IHttpActionResult Post(ResponseSongModel song)
        {
            if (this.ModelState.IsValid)
            {
                Artist artitst = this.data.Artists.GetById(song.ArtistId);
                Album album = this.data.Albums.GetById(song.AlbumId);

                if (album != null && artitst != null)
                {
                    this.data.Songs.Add(Mapper.Map<Song>(song));
                    int rowsChanged = this.data.SaveChanges();

                    return this.Ok($"Rows affected ({rowsChanged})");
                }
            }

            return this.BadRequest(this.ModelState);
        }
Exemplo n.º 7
0
        public IHttpActionResult Put(ResponseSongModel song)
        {
            if (this.ModelState.IsValid)
            {
                Song theSongToUpdate = this.data.Songs.GetById(song.Id);
                if (this.data.Songs.GetById(song.Id) == null)
                {
                    return(this.BadRequest($"Song with this id not found! Actual: {song.Id}"));
                }

                Mapper.DynamicMap(song, theSongToUpdate);
                this.data.Songs.Update(theSongToUpdate);

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

            return(this.BadRequest(this.ModelState));
        }
Exemplo n.º 8
0
        public IHttpActionResult Put(ResponseSongModel song)
        {
            if (this.ModelState.IsValid)
            {
                Song theSongToUpdate = this.data.Songs.GetById(song.Id);
                if (this.data.Songs.GetById(song.Id) == null)
                {
                    return this.BadRequest($"Song with this id not found! Actual: {song.Id}");
                }

                Mapper.DynamicMap(song, theSongToUpdate);
                this.data.Songs.Update(theSongToUpdate);

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

            return this.BadRequest(this.ModelState);
        }
Exemplo n.º 9
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());
            }
        }
Exemplo n.º 10
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());
            }
        }
Exemplo n.º 11
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");
        }