Пример #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");
        }
Пример #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!"));
        }
Пример #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;
        }
Пример #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;
        }
Пример #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));
        }
Пример #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);
        }
Пример #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));
        }
Пример #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);
        }
Пример #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());
            }
        }
Пример #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());
            }
        }
Пример #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");
        }