コード例 #1
0
        public IActionResult Post(int id, [FromQuery] bool?copyAllDays, [FromBody] ShiftModel shift)
        {
            if (shift == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(new ObjectResult(ModelState));
            }

            Schedule schedule = GetSchedule(id);

            UserCanAccessOrganization(schedule.Organization.OrganizationId);

            var positions = GetAvailableSchedulePositions(schedule);

            if (copyAllDays.HasValue && copyAllDays.Value)
            {
                foreach (DayOfWeek day in Enum.GetValues(typeof(DayOfWeek)))
                {
                    var shiftEntity = shift.Export(positions);
                    shiftEntity.Day      = day.ToString();
                    shiftEntity.Schedule = schedule;

                    _schedulerContext.Shifts.Add(shiftEntity);
                }
            }
            else
            {
                var shiftEntity = shift.Export(positions);
                shiftEntity.Schedule = schedule;

                _schedulerContext.Shifts.Add(shiftEntity);
            }

            _schedulerContext.SaveChanges();

            return(new ObjectResult(shift));
        }
コード例 #2
0
        public IActionResult Put(int id, [FromBody] ShiftModel shift)
        {
            if (shift == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(new ObjectResult(ModelState));
            }

            var shiftEntity = _schedulerContext.Shifts
                              .Include(s => s.Schedule)
                              .Include(s => s.Schedule.Organization)
                              .Single(o => o.ShiftId == id);

            UserCanAccessOrganization(shiftEntity.Schedule.Organization.OrganizationId);

            shift.Export(shiftEntity, GetAvailableSchedulePositions(shiftEntity.Schedule));
            _schedulerContext.SaveChanges();

            return(new ObjectResult(shift));
        }