public PriceDTO GetPriceById(int priceId) { CinemaPrice priceFromDb = _cinemaDbContext.CinemaPrices.FirstOrDefault(x => x.PriceId == priceId); if (priceFromDb == null) { return(null); } return(new PriceDTO { PriceId = priceFromDb.PriceId, Price = priceFromDb.Price, }); }
public int GetOrAddPriceInDb(int price) { CinemaPrice priceFromDb = _cinemaDbContext.CinemaPrices.FirstOrDefault(x => x.Price == price); if (priceFromDb != null) { return(priceFromDb.PriceId); } CinemaPrice insertPrice = new CinemaPrice { Price = price }; _cinemaDbContext.CinemaPrices.Add(insertPrice); _cinemaDbContext.SaveChanges(); return(insertPrice.PriceId); }