public async Task <SheriffAwayLocation> UpdateSheriffAwayLocation(SheriffAwayLocation sheriffAwayLocation) { _db.SheriffAwayLocation.Update(sheriffAwayLocation); await _db.SaveChangesAsync(); return(sheriffAwayLocation); }
private async Task <SheriffAwayLocation> CreateSheriffAwayLocationUsingDbContext() { var sheriffObject = await CreateSheriffUsingDbContext(); var newLocation = new Location { Name = "New PLace" }; await Db.Location.AddAsync(newLocation); await Db.SaveChangesAsync(); Detach(); var sheriffAwayLocation = new SheriffAwayLocation { LocationId = newLocation.Id, SheriffId = sheriffObject.Id, StartDate = DateTime.UtcNow, EndDate = DateTime.UtcNow.AddHours(3) }; await Db.SheriffAwayLocation.AddAsync(sheriffAwayLocation); await Db.SaveChangesAsync(); Detach(); return(sheriffAwayLocation); }
public async Task <SheriffAwayLocation> AddSheriffAwayLocation(SheriffAwayLocation sheriffAwayLocation) { await _db.SheriffAwayLocation.AddAsync(sheriffAwayLocation); await _db.SaveChangesAsync(); return(sheriffAwayLocation); }
private async Task SheriffEventTimeTestHelper(string awayLocationDate, string trainingDate, string trainingDate2) { var sheriffObject = await CreateSheriffUsingDbContext(); var newLocation = new Location { Name = "New PLace", AgencyId = "zfddf2342" }; await Db.Location.AddAsync(newLocation); var edmontonTimezoneLocation = new Location { Name = "CranbrookExample", AgencyId = "zfddf52342", Timezone = "America/Edmonton" }; await Db.Location.AddAsync(edmontonTimezoneLocation); await Db.SaveChangesAsync(); var sheriffAwayLocation = new SheriffAwayLocation { Timezone = "America/Vancouver", StartDate = DateTimeOffset.Parse($"{awayLocationDate} 00:00:00 -8"), EndDate = DateTimeOffset.Parse($"{awayLocationDate} 23:59:00 -8"), SheriffId = sheriffObject.Id, LocationId = edmontonTimezoneLocation.Id }; var result0 = HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await _controller.AddSheriffAwayLocation(sheriffAwayLocation.Adapt <SheriffAwayLocationDto>())); var sheriffTraining = new SheriffTraining { Timezone = "America/Edmonton", StartDate = DateTimeOffset.Parse($"{trainingDate} 00:00:00 -7"), EndDate = DateTimeOffset.Parse($"{trainingDate} 23:59:00 -7"), SheriffId = sheriffObject.Id }; HttpResponseTest.CheckForValid200HttpResponseAndReturnValue(await _controller.AddSheriffTraining(sheriffTraining.Adapt <SheriffTrainingDto>())); var sheriffTraining2 = new SheriffTraining { Timezone = "America/Edmonton", StartDate = DateTimeOffset.Parse($"{trainingDate2} 00:00:00 -7"), EndDate = DateTimeOffset.Parse($"{trainingDate2} 23:59:00 -7"), SheriffId = sheriffObject.Id }; HttpResponseTest.CheckForValid200HttpResponseAndReturnValue( await _controller.AddSheriffTraining(sheriffTraining2.Adapt <SheriffTrainingDto>())); }
public async Task <SheriffAwayLocation> AddSheriffAwayLocation(SheriffAwayLocation awayLocation) { ValidateStartAndEndDates(awayLocation.StartDate, awayLocation.EndDate); await ValidateSheriffExists(awayLocation.SheriffId); await ValidateNoOverlapAsync(awayLocation); awayLocation.Location = await Db.Location.FindAsync(awayLocation.LocationId); awayLocation.Sheriff = await Db.Sheriff.FindAsync(awayLocation.SheriffId); await Db.SheriffAwayLocation.AddAsync(awayLocation); await Db.SaveChangesAsync(); return(awayLocation); }
public async Task <SheriffAwayLocation> UpdateSheriffAwayLocation(SheriffAwayLocation awayLocation) { ValidateStartAndEndDates(awayLocation.StartDate, awayLocation.EndDate); await ValidateSheriffExists(awayLocation.SheriffId); var savedAwayLocation = await Db.SheriffAwayLocation.FindAsync(awayLocation.Id); savedAwayLocation.ThrowBusinessExceptionIfNull($"{nameof(SheriffAwayLocation)} with the id: {awayLocation.Id} could not be found. "); if (savedAwayLocation.ExpiryDate.HasValue) { throw new BusinessLayerException($"{nameof(SheriffAwayLocation)} with the id: {awayLocation.Id} has been expired"); } await ValidateNoOverlapAsync(awayLocation, awayLocation.Id); Db.Entry(savedAwayLocation).CurrentValues.SetValues(awayLocation); Db.Entry(savedAwayLocation).Property(x => x.SheriffId).IsModified = false; Db.Entry(savedAwayLocation).Property(x => x.ExpiryDate).IsModified = false; Db.Entry(savedAwayLocation).Property(x => x.ExpiryReason).IsModified = false; await Db.SaveChangesAsync(); return(savedAwayLocation); }
public async Task <SheriffAwayLocation> AddSheriffAwayLocation(DutyRosterService dutyRosterService, ShiftService shiftService, SheriffAwayLocation awayLocation, bool overrideConflicts) { ValidateStartAndEndDates(awayLocation.StartDate, awayLocation.EndDate); await ValidateSheriffExists(awayLocation.SheriffId); await ValidateNoOverlapAsync(dutyRosterService, shiftService, awayLocation, overrideConflicts); awayLocation.Location = await Db.Location.FindAsync(awayLocation.LocationId); awayLocation.Sheriff = await Db.Sheriff.FindAsync(awayLocation.SheriffId); await Db.SheriffAwayLocation.AddAsync(awayLocation); await Db.SaveChangesAsync(); return(awayLocation); }