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

            return(Ok(updatedSheriffAwayLocation));
        }
        public async Task <ActionResult <SheriffAwayLocationDto> > AddSheriffLeave(SheriffLeaveDto sheriffLeaveDto)
        {
            var sheriffLeave        = sheriffLeaveDto.Adapt <SheriffLeave>();
            var createdSheriffLeave = await _service.AddSheriffLeave(sheriffLeave);

            return(Ok(createdSheriffLeave));
        }
Beispiel #3
0
        public async Task <ActionResult <SheriffLeaveDto> > UpdateSheriffLeave(SheriffLeaveDto sheriffLeaveDto)
        {
            await CheckForAccessToSheriffByLocation <SheriffLeave>(sheriffLeaveDto.Id);

            var sheriffLeave        = sheriffLeaveDto.Adapt <SheriffLeave>();
            var updatedSheriffLeave = await SheriffService.UpdateSheriffLeave(sheriffLeave);

            return(Ok(updatedSheriffLeave.Adapt <SheriffLeaveDto>()));
        }
Beispiel #4
0
        public async Task <ActionResult <SheriffLeaveDto> > AddSheriffLeave(SheriffLeaveDto sheriffLeaveDto)
        {
            await CheckForAccessToSheriffByLocation(sheriffLeaveDto.SheriffId);

            var sheriffLeave        = sheriffLeaveDto.Adapt <SheriffLeave>();
            var createdSheriffLeave = await SheriffService.AddSheriffLeave(sheriffLeave);

            return(Ok(createdSheriffLeave.Adapt <SheriffLeaveDto>()));
        }
Beispiel #5
0
        public async Task <ActionResult <SheriffLeaveDto> > UpdateSheriffLeave(SheriffLeaveDto sheriffLeaveDto, bool overrideConflicts = false)
        {
            await CheckForAccessToSheriffByLocation <SheriffLeave>(sheriffLeaveDto.Id);

            var sheriffLeave        = sheriffLeaveDto.Adapt <SheriffLeave>();
            var updatedSheriffLeave = await SheriffService.UpdateSheriffLeave(DutyRosterService, ShiftService, sheriffLeave, overrideConflicts);

            return(Ok(updatedSheriffLeave.Adapt <SheriffLeaveDto>()));
        }
Beispiel #6
0
        public async Task AddUpdateRemoveSheriffLeave()
        {
            var sheriffObject = await CreateSheriffUsingDbContext();

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

            await Db.SaveChangesAsync();

            var lookupCode = new LookupCode
            {
                Code        = "zz4",
                Description = "gg",
                LocationId  = newLocation.Id
            };
            await Db.LookupCode.AddAsync(lookupCode);

            var lookupCode2 = new LookupCode
            {
                Code        = "zz",
                Description = "gg",
                LocationId  = newLocation.Id
            };

            await Db.LookupCode.AddAsync(lookupCode2);

            await Db.SaveChangesAsync();


            var entity = new SheriffLeaveDto
            {
                LeaveTypeId = lookupCode.Id,
                SheriffId   = sheriffObject.Id,
                StartDate   = DateTime.UtcNow,
                EndDate     = DateTime.UtcNow.AddHours(3)
            };

            //Add
            var controllerResult = await _controller.AddSheriffLeave(entity);

            var response = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult);

            Assert.Equal(entity.LeaveTypeId, response.LeaveType.Id);
            Assert.Equal(entity.SheriffId, response.SheriffId);
            Assert.Equal(entity.StartDate, response.StartDate);
            Assert.Equal(entity.EndDate, response.EndDate);

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

            var response2 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult2);

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

            Detach();

            var updateSheriffLeave = entity.Adapt <SheriffLeaveDto>();

            updateSheriffLeave.StartDate = DateTime.UtcNow.AddDays(5);
            updateSheriffLeave.EndDate   = DateTime.UtcNow.AddDays(5);
            //updateSheriffLeave.LeaveTypeId = lookupCode2.Id;

            updateSheriffLeave.LeaveType   = lookupCode2.Adapt <LookupCodeDto>();
            updateSheriffLeave.LeaveTypeId = lookupCode2.Id;
            updateSheriffLeave.Id          = response.Id;

            //Update
            var controllerResult3 = await _controller.UpdateSheriffLeave(updateSheriffLeave);

            var response3 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult3);

            Assert.Equal(response3.StartDate, updateSheriffLeave.StartDate);
            Assert.Equal(response3.EndDate, updateSheriffLeave.EndDate);
            Assert.Equal(response3.SheriffId, updateSheriffLeave.SheriffId);
            Assert.Equal(response3.LeaveTypeId, updateSheriffLeave.LeaveTypeId);

            //Remove
            var controllerResult4 = await _controller.RemoveSheriffLeave(updateSheriffLeave.Id, "expired");

            HttpResponseTest.CheckForNoContentResponse(controllerResult4);

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

            var response5 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(controllerResult5);

            Assert.Empty(response5.Leave);
        }