Exemplo n.º 1
0
        public async Task <IActionResult> Edit(ShiftVM shiftModel)
        {
            // Check that the data is present
            if (!ModelState.IsValid || shiftModel.ShiftId == 0)
            {
                return(BadRequest());
            }

            // Check that the shift exists
            Shift shift = await _shiftService.GetShift(shiftModel.ShiftId);

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

            // Check that the user has management access
            string userId = _userManager.GetUserId(User);
            Member member = await _memberService.GetMember(shift.Location.GroupId, userId);

            if (member == null || !member.Approved || !member.CanManageShifts)
            {
                return(BadRequest());
            }

            shift.Start           = shiftModel.Start;
            shift.End             = shiftModel.End;
            shift.MinParticipants = shiftModel.MinParticipants;
            shift.MaxParticipants = shiftModel.MaxParticipants;
            shift.Instructions    = shiftModel.Instructions;

            await _shiftService.EditShift(shift);

            return(Ok());
        }