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));
        }
예제 #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>()));
        }
예제 #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>()));
        }
예제 #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>()));
        }
예제 #6
0
        public async Task SheriffOverrideConflictRemove()
        {
            var sheriffObject = await CreateSheriffUsingDbContext();

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

            await Db.SaveChangesAsync();

            var startDate = DateTimeOffset.UtcNow.Date.AddHours(1);
            var endDate   = startDate.AddHours(8);

            var shift = new Shift
            {
                Id         = 9000665,
                StartDate  = startDate,
                EndDate    = endDate,
                LocationId = newLocation.Id,
                Timezone   = "America/Vancouver",
                SheriffId  = sheriffObject.Id
            };

            Db.Shift.Add(shift);

            var duty = new Duty
            {
                LocationId = newLocation.Id,
            };

            Db.Duty.Add(duty);

            await Db.SaveChangesAsync();

            var dutySlot = new DutySlot
            {
                SheriffId  = sheriffObject.Id,
                LocationId = newLocation.Id,
                StartDate  = startDate,
                EndDate    = endDate,
                DutyId     = duty.Id
            };

            Db.DutySlot.Add(dutySlot);

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

            await Db.SaveChangesAsync();

            var entity = new SheriffLeaveDto
            {
                LeaveTypeId = lookupCode.Id,
                SheriffId   = sheriffObject.Id,
                StartDate   = startDate,
                EndDate     = endDate
            };

            Assert.True(Db.Shift.Any(s => s.ExpiryDate == null && s.Id == shift.Id));
            Assert.True(Db.DutySlot.Any(ds => ds.ExpiryDate == null && ds.Id == dutySlot.Id));

            await _controller.AddSheriffLeave(entity, true);

            Assert.False(Db.Shift.Any(s => s.ExpiryDate == null && s.Id == shift.Id));
            Assert.False(Db.DutySlot.Any(ds => ds.ExpiryDate == null && ds.Id == dutySlot.Id));
        }
예제 #7
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);
        }