コード例 #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);
                }
            }
        }
コード例 #3
0
 public Album Save(Album album)
 {
     var albumRepo = Mapper.Map<AlbumRepo>(album);
     NH.Run(s => s.SaveOrUpdate(albumRepo));
     return Mapper.Map<Album>(albumRepo);
 }
コード例 #4
0
 public void Delete(Album album)
 {
     var albumRepo = Mapper.Map<AlbumRepo>(album);
     NH.Run(s => s.Delete(albumRepo));
 }
コード例 #5
0
 public Album Save(Album album)
 {
     return _albumDao.Save(album);
 }
コード例 #6
0
 public void Delete(Album album)
 {
     _albumDao.Delete(album);
 }