Пример #1
0
        private static void UpdateAlbum()
        {
            Console.WriteLine("Update album");
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:7527/");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var album = new Album()
                {
                    Title = "New",
                    Year = 1997
                };
                HttpResponseMessage response = client.PutAsJsonAsync("api/album/2", album).Result;

                if (response.IsSuccessStatusCode)
                {
                    Console.WriteLine("Update succsessful");
                }
                else
                {
                    Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
                }
            }
        }
Пример #2
0
        private static void PostAlbum()
        {
            Console.WriteLine("Post album");
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:7527/");
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                var album = new Album()
                {
                    Title = "Telerik",
                    Year = 2015,
                    Producer = "Niki"
                };

                var postContent = new StringContent(JsonConvert.SerializeObject(album));
                postContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                HttpResponseMessage response = client.PostAsync("api/album", postContent).Result;

                if (response.IsSuccessStatusCode)
                {
                    Console.WriteLine("Post succsessful");
                }
                else
                {
                    Console.WriteLine("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
                }
            }
        }
 public Album Save(Album album)
 {
     var albumRepo = Mapper.Map<AlbumRepo>(album);
     NH.Run(s => s.SaveOrUpdate(albumRepo));
     return Mapper.Map<Album>(albumRepo);
 }
 public void Delete(Album album)
 {
     var albumRepo = Mapper.Map<AlbumRepo>(album);
     NH.Run(s => s.Delete(albumRepo));
 }
 public Album Save(Album album)
 {
     return _albumDao.Save(album);
 }
 public void Delete(Album album)
 {
     _albumDao.Delete(album);
 }