private static async void PostRequests(HttpClient client)
        {
            var sampleArtist = new ArtistServiceModel
            {
                Name        = "Pesho Testa",
                Country     = "Bulgaria",
                DateOfBirth = new DateTime(1989, 10, 10)
            };

            var sampleSong = new SongServiceModel
            {
                Title      = "Pesen za Pesho",
                ReleasedOn = new DateTime(2015, 10, 10),
                Artist     = sampleArtist.Name,
                Genre      = "Punk"
            };

            var sampleAlbum = new AlbumServiceModel
            {
                Title   = "Pesho 2",
                Genre   = "Psychedelic",
                Artists = new List <string> {
                    "Pesho Testa"
                },
                Songs = new List <string> {
                    "Pesen za Pesho"
                }
            };

            var httpResponseArtist = await client.PostAsJsonAsync("api/Artists", sampleArtist);

            var httpResponseSong = await client.PostAsJsonAsync("api/Songs", sampleSong);

            var httpResponseAlbum = await client.PostAsJsonAsync("api/Albums", sampleAlbum);
        }
Example #2
0
        /// <summary>
        ///Update record in table tbl_Album
        /// </summary>
        public AlbumServiceModel UpdateAlbum(AlbumServiceModel albumModel)
        {
            Album coreAlbum = _albumRepository.GetById(albumModel.AlbumID);

            albumModel.PopulateCoreEntityFromModel(coreAlbum);
            _albumRepository.Update(coreAlbum);
            albumModel.PopulateModelFromCoreEntity(coreAlbum);
            return(albumModel);
        }
Example #3
0
        /// <summary>
        ///Isert record in table tbl_Album
        /// </summary>
        public AlbumServiceModel InsertAlbum(AlbumServiceModel albumModel)
        {
            Album coreAlbum = new Album();

            albumModel.PopulateCoreEntityFromModel(coreAlbum);
            _albumRepository.Insert(coreAlbum);
            albumModel.PopulateModelFromCoreEntity(coreAlbum);
            return(albumModel);
        }
Example #4
0
        /// <summary>
        /// method to Get record from tbl_Album table
        /// </summary>
        public List <AlbumServiceModel> GetAlbumData()
        {
            List <AlbumServiceModel> albumList = new List <AlbumServiceModel>();

            foreach (Album item in _albumRepository.Table.ToList <Album>())
            {
                AlbumServiceModel currentItem = new AlbumServiceModel();
                currentItem.PopulateModelFromCoreEntity(item);
                albumList.Add(currentItem);
            }
            return(albumList);
        }
Example #5
0
        // POST api/Albums
        public IHttpActionResult Post([FromBody] AlbumServiceModel value)
        {
            var artists = new GenericRepository <Artist>(Data);
            var songs   = new GenericRepository <Song>(Data);

            if (value.Artists != null)
            {
                foreach (var artist in value.Artists)
                {
                    if (!artists.All().Any(x => x.Name == artist))
                    {
                        var newArtist = new Artist {
                            Name = artist
                        };
                        artists.Add(newArtist);
                    }

                    Data.SaveChanges();
                }
            }

            if (value.Songs != null)
            {
                foreach (var song in value.Songs)
                {
                    if (!songs.All().Any(x => x.Title == song))
                    {
                        var newSong = new Song {
                            Title = song
                        };
                        songs.Add(newSong);
                    }

                    Data.SaveChanges();
                }
            }

            var album = new Album
            {
                Title      = value.Title,
                Genre      = value.Genre,
                ReleasedOn = value.ReleasedOn,
                Artists    = artists.All().Where(x => value.Artists.Contains(x.Name)).ToList(),
                Songs      = songs.All().Where(x => value.Songs.Contains(x.Title)).ToList()
            };

            AlbumsRepository.Add(album);
            Data.SaveChanges();
            return(this.StatusCode(HttpStatusCode.Created));
        }
Example #6
0
        public ActionResult AlbumDetail(AlbumDetailModel model)
        {
            AlbumServiceModel albumEntity = new AlbumServiceModel();

            albumEntity.AlbumName   = model.AlbumName;
            albumEntity.Artist      = model.Artist;
            albumEntity.Genre       = model.Genre;
            albumEntity.CreatedBy   = "Vivek";
            albumEntity.DateCreated = DateTime.Now;
            albumEntity.UpdatedBy   = "Vivek";
            albumEntity.DateUpdated = DateTime.Now;

            _mvcsService.InsertAlbum(albumEntity);
            return(RedirectToAction("Home", "AlbumHome"));
        }
Example #7
0
        // PUT api/Albums/5
        public IHttpActionResult Put(int id, [FromBody] AlbumServiceModel value)
        {
            var albumToUpdate = AlbumsRepository.All().FirstOrDefault(x => x.AlbumId == id);

            if (albumToUpdate == null)
            {
                return(this.BadRequest("No such album"));
            }

            var artists = new GenericRepository <Artist>(Data);
            var songs   = new GenericRepository <Song>(Data);

            if (value.Artists != null)
            {
                foreach (var artist in value.Artists)
                {
                    if (!artists.All().Any(x => x.Name == artist))
                    {
                        var newArtist = new Artist {
                            Name = artist
                        };
                        artists.Add(newArtist);
                    }

                    Data.SaveChanges();
                }

                albumToUpdate.Artists = artists.All().Where(x => value.Artists.Contains(x.Name)).ToList();
            }

            if (value.Songs != null)
            {
                foreach (var song in value.Songs)
                {
                    if (!songs.All().Any(x => x.Title == song))
                    {
                        var newSong = new Song {
                            Title = song
                        };
                        songs.Add(newSong);
                    }

                    Data.SaveChanges();
                }

                albumToUpdate.Songs = songs.All().Where(x => value.Songs.Contains(x.Title)).ToList();
            }

            if (value.Title != null)
            {
                albumToUpdate.Title = value.Title;
            }

            if (value.Genre != null)
            {
                albumToUpdate.Genre = value.Genre;
            }

            if (value.ReleasedOn != null)
            {
                albumToUpdate.ReleasedOn = value.ReleasedOn;
            }

            Data.SaveChanges();

            return(this.ResponseMessage(new HttpResponseMessage(HttpStatusCode.Accepted)));
        }