public void Post(int[] albumsIds) { int currentWeekday = (int)((DayOfWeek)Enum.Parse(typeof(DayOfWeek), DateTime.Now.DayOfWeek.ToString())); IList <Albums> albums = _repoAlbums.Find(c => albumsIds.Contains(c.AlbumsId)).ToList(); IList <CashBack> cashback = _repoCash.Find(c => c.Weekday == currentWeekday).ToList(); Albums album; Sales sale = new Sales(); sale.Date = DateTime.Now; AlbumsSold albumSold; foreach (int id in albumsIds) { album = albums.Where(c => c.AlbumsId == id).FirstOrDefault(); if (album != null) { albumSold = new AlbumsSold(); albumSold.AlbumsId = album.AlbumsId; albumSold.Price = album.Price; albumSold.CashBack = cashback.Where(c => c.Genre == album.Genre).FirstOrDefault().value; sale.Albums.Add(albumSold); } } _repo.Add(sale); _repo.SaveChanges(); }
public ActionResult <Albums> Get(int id) { return(_repo.Find(c => c.AlbumsId == id).FirstOrDefault()); }