예제 #1
0
        public IHttpActionResult Put(int id, SongApiModel song)
        {
            if (song == null)
            {
                return(this.BadRequest("No data"));
            }

            if (this.songService.Update(id, song.Title, song.ArtistId, song.Genre, song.Year))
            {
                return(this.Ok());
            }

            return(this.NotFound());
        }
        public IHttpActionResult Put(int id, SongApiModel song)
        {
            if (song == null)
            {
                return this.BadRequest("No data");
            }

            if (this.songService.Update(id, song.Title, song.ArtistId, song.Genre, song.Year))
            {
                return this.Ok();
            }

            return this.NotFound();
        }
예제 #3
0
        public IHttpActionResult Post(SongApiModel song)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            if (song == null)
            {
                return(this.BadRequest("No data"));
            }

            this.songService.Add(song.Title, song.ArtistId, song.Genre, song.Year);

            return(this.Ok());
        }
        public IHttpActionResult Post(SongApiModel song)
        {
            if (!this.ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            if (song == null)
            {
                return this.BadRequest("No data");
            }

            this.songService.Add(song.Title, song.ArtistId, song.Genre, song.Year);

            return this.Ok();
        }
예제 #5
0
        static void Main(string[] args)
        {
            var httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(ServerAddress);

            // Artists with JSON
            var artist = new ArtistApiModel()
            {
                Name = "Pesho123", Country = "Bulgaria", DateOfBirth = DateTime.Now
            };

            Console.WriteLine("Adding following artist " + artist);
            Console.WriteLine("-----------------------------------");
            Artist.Add(httpClient, artist);
            Console.ReadLine();
            Console.WriteLine("Listing all artists");
            Console.WriteLine("-----------------------------------");
            Artist.Print(httpClient);
            Console.ReadLine();
            var updatedArtist = new ArtistApiModel()
            {
                Name = "PeshoUpdated", Country = "Zimbabve", DateOfBirth = DateTime.Now
            };

            Console.WriteLine("Update artist with ID 1 to " + updatedArtist);
            Console.WriteLine("-----------------------------------");
            Artist.Update(httpClient, 1, artist);
            Console.ReadLine();
            Console.WriteLine("Delete artist with ID 1");
            Console.WriteLine("-----------------------------------");
            Artist.Delete(httpClient, 1);
            Console.ReadLine();

            // Songs with XML
            var song = new SongApiModel()
            {
                Title = "Nothing else matters", Genre = "Blues", Year = 1995, ArtistId = 1
            };

            Song.Add(httpClient, song);
            Console.ReadLine();

            Console.WriteLine("-----------------------------------");
            Song.Print(httpClient);
            Console.ReadLine();
        }
예제 #6
0
        public static async void Add(HttpClient httpClient, SongApiModel song)
        {
            var response = await httpClient.PostAsXmlAsync("song", song);

            Console.WriteLine("Done!");
        }