public IActionResult CopySchedule([FromBody] ScheduleCopyTargetDto scheduleCopyTarget)
        {
            Result result = scheduleService.CopySchedule(scheduleCopyTarget);

            if (result.Success)
            {
                return(Ok(result.Success));
            }
            else
            {
                if (result.Exception != null)
                {
                    Log.Error(result.Exception, "Error copying schedule!");
                    return(StatusCode(500));
                }
                else
                {
                    Log.Warning("Unable to copy schedule!");
                    return(Conflict());
                }
            }
        }
Exemplo n.º 2
0
        public Result CopySchedule(ScheduleCopyTargetDto scheduleCopyTarget)
        {
            if (scheduleCopyTarget.ScheduleSlotIds == null)
            {
                return(new Result());
            }
            int lastCopyTargetId = scheduleCopyTarget.ScheduleSlotIds.Last();

            for (int i = 0; i < scheduleCopyTarget.ScheduleSlotIds.Count; i++)
            {
                ScheduleSlotDto original     = GetScheduleSlotById(scheduleCopyTarget.ScheduleSlotIds.ElementAt(i));
                ScheduleSlotDto scheduleSlot = new ScheduleSlotDto()
                {
                    MovieId      = original.MovieId,
                    ScheduleId   = original.ScheduleId,
                    Reservations = new List <ReservationDto>()
                };

                TimeSpan diff = scheduleCopyTarget.TargetDate.ToLocalTime().Date.Subtract(original.Start);

                scheduleSlot.Start = original.Start.Add(diff).ToLocalTime();
                scheduleSlot.End   = original.End.Add(diff).ToLocalTime();

                Result result = scheduleRepository.ScheduleMovie(scheduleCopyTarget.RoomIds.ElementAt(i), parser.ToScheduleSlot(scheduleSlot));
                if (!result.Success)
                {
                    if (result.Exception == null)
                    {
                        Log.Warning("Couldn't copy schedule slot with id {0}!", scheduleSlot.Id);
                    }
                    else
                    {
                        Log.Error(result.Exception, "Exception thrown while trying to copy schedule slot with id {0}!", scheduleSlot.Id);
                    }
                }
            }

            return(new Result());
        }