public Tuple <int, string> RegisterVehicle(Vehicle vehicle) { using (HuboDbContext ctx = new HuboDbContext()) { try { int result = 0; // check rego number doesn't already exist if (ctx.VehicleSet.Any(o => o.RegistrationNo == vehicle.RegistrationNo)) { // Match! return(Tuple.Create(-1, "Registration Number already exists")); } ctx.Entry(vehicle).State = System.Data.Entity.EntityState.Added; result = ctx.SaveChanges(); return(Tuple.Create(vehicle.Id, "Success")); } catch (Exception ex) { return(Tuple.Create(-1, ex.Message)); } } }
public Tuple <int, string> StopDriving(DrivingShift shiftDetails) { using (HuboDbContext ctx = new HuboDbContext()) { try { DrivingShift shift = ctx.DrivingShiftSet.Single <DrivingShift>(s => s.Id == shiftDetails.Id); if (shift.isActive == false) { return(Tuple.Create(-1, "Driving shift has already ended")); } shift.StopDrivingDateTime = shiftDetails.StopDrivingDateTime; shift.StopHubo = shiftDetails.StopHubo; shift.EndNote = shiftDetails.EndNote; shift.isActive = false; ctx.Entry(shift).State = EntityState.Modified; ctx.SaveChanges(); return(Tuple.Create(1, "Success")); } catch (ArgumentNullException ex) { return(Tuple.Create(-1, ex.Message)); } catch (Exception ex) { return(Tuple.Create(-1, ex.Message)); } } }
public Tuple <int, string> StopBreak(Break stopBreak) { using (HuboDbContext ctx = new HuboDbContext()) { try { Break currentBreak = ctx.BreakSet.Single <Break>(b => b.Id == stopBreak.Id); if (currentBreak.isActive == false) { return(Tuple.Create(-1, "Break has already ended")); } currentBreak.isActive = false; currentBreak.StopBreakDateTime = stopBreak.StopBreakDateTime; currentBreak.StopBreakLocation = stopBreak.StopBreakLocation; currentBreak.EndNote = stopBreak.EndNote; ctx.Entry(currentBreak).State = EntityState.Modified; ctx.SaveChanges(); return(Tuple.Create(1, "Success")); } catch (ArgumentNullException ex) { return(Tuple.Create(-1, ex.Message)); } catch (Exception ex) { return(Tuple.Create(-1, ex.Message)); } } }
public Tuple <int, string> StopShift(WorkShift shift) { using (HuboDbContext ctx = new HuboDbContext()) { try { WorkShift currentShift = ctx.WorkShiftSet.Single <WorkShift>(s => s.Id == shift.Id); if (currentShift.isActive == false) { return(Tuple.Create(-1, "Shift has already ended")); } currentShift.EndDate = shift.EndDate; currentShift.EndLocationLat = shift.EndLocationLat; currentShift.EndLocationLong = shift.EndLocationLong; currentShift.EndLocation = shift.EndLocation; currentShift.EndNote = shift.EndNote; currentShift.isActive = false; ctx.Entry(currentShift).State = EntityState.Modified; ctx.SaveChanges(); return(Tuple.Create(1, "Success")); } catch (ArgumentNullException ex) { return(Tuple.Create(-1, ex.Message)); } catch (Exception ex) { return(Tuple.Create(-1, ex.Message)); } } }