public void Add(string caption, string address, int?cinemaNetworkId, string city, string description, string email, string phoneNumber) { CinemaNetworkEntity network = this.unitOfWork.CinemaNetworkRepository.GetById(cinemaNetworkId ?? 1); if (network == null) { network = new CinemaNetworkEntity() { Id = 1, WebSite = "Vizoria.ua" }; this.unitOfWork.CinemaNetworkRepository.Add(network); this.unitOfWork.SaveChanges(); } CinemaEntity cinema = new CinemaEntity() { CinemaNetworkId = network?.Id, Address = address, Caption = caption, Description = description, City = CityConverter.ConvertStringToEnum(city), Email = email, PhoneNumber = phoneNumber }; this.unitOfWork.CinemaRepository.Add(cinema); this.unitOfWork.SaveChanges(); }
public static CinemaResponse CinemaEntityToResponse(CinemaEntity cinemaEntity) { CinemaResponse cinemaResponse = new CinemaResponse() { Name = cinemaEntity.Name, CityId = cinemaEntity.CityId }; return(cinemaResponse); }
public static CinemaEntity CinemaResponseToEntity(CinemaResponse cinemaResponse) { CinemaEntity cinemaEntity = new CinemaEntity() { Name = cinemaResponse.Name, CityId = cinemaResponse.CityId }; return(cinemaEntity); }
public CinemaResponse GetCinema(int id) { CinemaEntity cinemaEntity = db.Cinemas.Find(id); if (cinemaEntity == null) { return(null); } return(Converter.CinemaEntityToResponse(cinemaEntity)); }
public void Update(int id, string caption, string address, int?cinemaNetworkId, string city, string description, string email, string phoneNumber) { CinemaEntity cinema = this.unitOfWork.CinemaRepository.GetById(id); CinemaNetworkEntity network = this.unitOfWork.CinemaNetworkRepository.GetById(cinemaNetworkId ?? 0); cinema.CinemaNetworkId = network.Id; cinema.Address = address; cinema.Caption = caption; cinema.Description = description; cinema.City = CityConverter.ConvertStringToEnum(city); cinema.Email = email; cinema.PhoneNumber = phoneNumber; this.unitOfWork.CinemaRepository.Update(cinema); this.unitOfWork.SaveChanges(); }
public ActionResult <CinemaResponse> PostCinema(CinemaEntity cinemaEntity) { if (!ModelState.IsValid) { return(BadRequest()); } CinemaResponse cinemaResponse = cinemaServices.SaveCinema(cinemaEntity); if (cinemaResponse == null) { return(BadRequest()); } return(CreatedAtAction("GetCinema", new { id = cinemaEntity.Id }, cinemaResponse)); }
public CinemaResponse SaveCinema(CinemaEntity cinemaEntity) { db.Cinemas.Add(cinemaEntity); try { db.SaveChanges(); } catch (DbEntityValidationException) { return(null); } CinemaResponse cinemaResponse = Converter.CinemaEntityToResponse(cinemaEntity); return(cinemaResponse); }
public async Task <int> UpsertCinemaAsync(CinemaEntity cinemaEntity) { try { using (IDbConnection dbConnection = new SqlConnection(_settings.ConnectionString)) { int cinemaId = await dbConnection.QuerySingleOrDefaultAsync <int>( "UpsertCinema", cinemaEntity, commandType : CommandType.StoredProcedure ); return(cinemaId); } } catch (SqlException e) { throw new UniqueIndexException("UpsertCinema", e); } }