Exemple #1
0
        private void checkSupportedFormat(ShowTimeCreateDto dto)
        {
            Room room = roomService.GetDetail(dto.RoomId);

            if (!room.Formats.Contains(dto.Format.ToString()))
            {
                throw new Exception("Not support the format " + dto.Format + ". Only " + room.Formats + ".");
            }
        }
Exemple #2
0
        public ShowTime Create(ShowTimeCreateDto dto)
        {
            checkSupportedFormat(dto);
            checkDuplicated(dto);

            var entity = new ShowTime {
                RoomId     = dto.RoomId,
                TheaterId  = roomService.GetDetail(dto.RoomId).TheaterId,
                MovieId    = dto.MovieId,
                ExtraPrice = dto.ExtraPrice,
                Status     = dto.Status,
                Type       = dto.Type,
                Format     = dto.Format,
                Time       = dateTimeUtils.Parse(dto.Time)
            };

            return(repository.Add(entity));
        }
Exemple #3
0
        private void checkDuplicated(ShowTimeCreateDto dto, int exceptId = 0)
        {
            Movie           movie     = movieRepository.FindById(dto.MovieId);
            List <ShowTime> showTimes = GetByRoomId(dto.RoomId);
            DateTime        time      = dateTimeUtils.Parse(dto.Time);

            ShowTime dupplicated = showTimes.Where(s => {
                var start      = s.Time;
                var end        = start.AddMinutes(s.Movie.Length);
                bool isBetween = start <= time && time <= end;
                return(s.Id != exceptId && isBetween);
            }).FirstOrDefault();

            if (dupplicated != null)
            {
                DateTime dupEnd = dupplicated.Time.AddMinutes(dupplicated.Movie.Length);
                throw new Exception("Room is not available until " + dupEnd.ToString(dateTimeUtils.FORMAT));
            }
        }