Esempio 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());
        }
Esempio n. 2
0
        public async Task GetShiftThrowsOnShiftId()
        {
            var service = new ShiftService(_client, TestDb, TestContainer);
            var fixture = new Fixture();

            var testId = fixture.Create <string>();

            var func = new Func <Task>(() => service.GetShift(testId, null));
            await func.Should().ThrowAsync <ArgumentException>();
        }
Esempio n. 3
0
        public async Task GetShiftReturnsCorrectShift()
        {
            var service = new ShiftService(_client, TestDb, TestContainer);

            var fixture       = new Fixture();
            var testShifts    = fixture.CreateMany <Shift>();
            var expectedShift = testShifts.Skip(1).Take(1).First();

            await _client.CreateDatabaseIfNotExistsAsync(TestDb);

            await _client.GetDatabase(TestDb).CreateContainerIfNotExistsAsync(TestContainer, "/userId");

            foreach (var shift in testShifts)
            {
                await _client.GetContainer(TestDb, TestContainer).CreateItemAsync(shift, new PartitionKey(shift.UserId));
            }

            var actual = await service.GetShift(expectedShift.UserId, expectedShift.Id);

            actual.Should().BeEquivalentTo(expectedShift);
        }