public static HallResponse HallEntityToResponse(HallEntity hallEntity)
        {
            HallResponse hallResponse = new HallResponse()
            {
                Name     = hallEntity.Name,
                Capacity = hallEntity.Capacity,
                CinemaId = hallEntity.CinemaId
            };

            return(hallResponse);
        }
        public static HallEntity HallResponseToEntity(HallResponse hallResponse)
        {
            HallEntity hallEntity = new HallEntity()
            {
                Name     = hallResponse.Name,
                Capacity = hallResponse.Capacity,
                CinemaId = hallResponse.CinemaId
            };

            return(hallEntity);
        }
        public HallResponse GetHall(int id)
        {
            HallEntity hallEntity = db.Halls.Find(id);

            if (hallEntity == null)
            {
                return(null);
            }

            return(Converter.HallEntityToResponse(hallEntity));
        }
        public HallResponse SaveHall(HallEntity hallEntity)
        {
            db.Halls.Add(hallEntity);

            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException)
            {
                return(null);
            }

            HallResponse hallResponse = Converter.HallEntityToResponse(hallEntity);

            return(hallResponse);
        }
Beispiel #5
0
        public ActionResult <HallResponse> PostHall(HallEntity hallEntity, int cinemaId)
        {
            if (!ModelState.IsValid || cinemaServices.GetCinema(cinemaId) == null)
            {
                return(BadRequest());
            }

            hallEntity.CinemaId = cinemaId;

            HallResponse hallResponse = hallServices.SaveHall(hallEntity);

            if (hallResponse == null)
            {
                return(BadRequest());
            }

            return(CreatedAtAction("GetHall", new { id = hallEntity.Id }, hallResponse));
        }
        public async Task <int> UpsertHallAsync(HallEntity hallEntity)
        {
            try
            {
                using (IDbConnection dbConnection = new SqlConnection(_settings.ConnectionString))
                {
                    int hallId = await dbConnection.QuerySingleOrDefaultAsync <int>(
                        "UpsertHall",
                        hallEntity,
                        commandType : CommandType.StoredProcedure
                        );

                    return(hallId);
                }
            }
            catch (SqlException e)
            {
                throw new UniqueIndexException("UpsertHall", e);
            }
        }