public async Task <ActionResult> UpdateSheriffAwayLocation(SheriffAwayLocationDto sheriffAwayLocationDto)
        {
            var sheriffAwayLocation        = sheriffAwayLocationDto.Adapt <SheriffAwayLocation>();
            var updatedSheriffAwayLocation = await _service.UpdateSheriffAwayLocation(sheriffAwayLocation);

            return(Ok(updatedSheriffAwayLocation));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <SheriffAwayLocationDto> > UpdateSheriffAwayLocation(SheriffAwayLocationDto sheriffAwayLocationDto)
        {
            await CheckForAccessToSheriffByLocation <SheriffAwayLocation>(sheriffAwayLocationDto.Id);

            var sheriffAwayLocation        = sheriffAwayLocationDto.Adapt <SheriffAwayLocation>();
            var updatedSheriffAwayLocation = await SheriffService.UpdateSheriffAwayLocation(sheriffAwayLocation);

            return(Ok(updatedSheriffAwayLocation.Adapt <SheriffAwayLocationDto>()));
        }
Ejemplo n.º 3
0
        public async Task AddUpdateRemoveSheriffAwayLocation()
        {
            //Test permissions?
            var sheriffObject = await CreateSheriffUsingDbContext();

            var newLocation = new Location {
                Name = "New PLace", AgencyId = "545325345353"
            };
            await Db.Location.AddAsync(newLocation);

            var newLocation2 = new Location {
                Name = "New PLace", AgencyId = "g435346346363"
            };
            await Db.Location.AddAsync(newLocation2);

            await Db.SaveChangesAsync();

            var sheriffAwayLocation = new SheriffAwayLocationDto
            {
                SheriffId  = sheriffObject.Id,
                LocationId = newLocation.Id,
                StartDate  = DateTime.UtcNow,
                EndDate    = DateTime.UtcNow.AddHours(3)
            };

            //Add
            var controllerResult = await _controller.AddSheriffAwayLocation(sheriffAwayLocation);

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Equal(sheriffAwayLocation.LocationId, response.Location.Id);
            Assert.Equal(sheriffAwayLocation.SheriffId, response.SheriffId);
            Assert.Equal(sheriffAwayLocation.StartDate, response.StartDate);
            Assert.Equal(sheriffAwayLocation.EndDate, response.EndDate);

            Detach();

            var controllerResult2 = await _controller.GetSheriffForTeam(sheriffObject.Id);

            var response2 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult2);

            Assert.True(response2.AwayLocation.Count == 1);

            var updateSheriffAwayLocation = sheriffAwayLocation.Adapt <SheriffAwayLocationDto>();

            updateSheriffAwayLocation.StartDate  = DateTime.UtcNow.AddDays(5);
            updateSheriffAwayLocation.EndDate    = DateTime.UtcNow.AddDays(5);
            updateSheriffAwayLocation.LocationId = newLocation2.Id;
            updateSheriffAwayLocation.Id         = response.Id;

            Detach();

            //Update
            var controllerResult3 = await _controller.UpdateSheriffAwayLocation(updateSheriffAwayLocation);

            var response3 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult3);

            Assert.Equal(response3.StartDate, updateSheriffAwayLocation.StartDate);
            Assert.Equal(response3.EndDate, updateSheriffAwayLocation.EndDate);
            Assert.Equal(response3.SheriffId, updateSheriffAwayLocation.SheriffId);

            Detach();

            //Remove
            var controllerResult4 = await _controller.RemoveSheriffAwayLocation(response.Id, "hello");

            HttpResponseTest.CheckForNoContentResponse(controllerResult4);

            var controllerResult6 = await _controller.GetSheriffForTeam(sheriffObject.Id);

            var response6 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult6);

            Assert.Empty(response6.AwayLocation);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <SheriffAwayLocationDto> > UpdateSheriffAwayLocation(SheriffAwayLocationDto sheriffAwayLocationDto, bool overrideConflicts = false)
        {
            await CheckForAccessToSheriffByLocation <SheriffAwayLocation>(sheriffAwayLocationDto.Id);

            var sheriffAwayLocation        = sheriffAwayLocationDto.Adapt <SheriffAwayLocation>();
            var updatedSheriffAwayLocation = await SheriffService.UpdateSheriffAwayLocation(DutyRosterService, ShiftService, sheriffAwayLocation, overrideConflicts);

            return(Ok(updatedSheriffAwayLocation.Adapt <SheriffAwayLocationDto>()));
        }
        public async Task <ActionResult <SheriffAwayLocationDto> > AddSheriffAwayLocation(SheriffAwayLocationDto sheriffAwayLocationDto)
        {
            var sheriffAwayLocation        = sheriffAwayLocationDto.Adapt <SheriffAwayLocation>();
            var createdSheriffAwayLocation = await _service.AddSheriffAwayLocation(sheriffAwayLocation);

            return(Ok(createdSheriffAwayLocation));
        }