public Tuple <int, string> StartShift(WorkShift shift) { using (HuboDbContext ctx = new HuboDbContext()) { try { //if (!ctx.DriverSet.Any(d => d.Id == shift.DriverId)) //{ // //Driver ID does not exist // return Tuple.Create(-1, "No Driver exists with the ID = " + shift.DriverId); //} //if (!ctx.CompanySet.Any(c => c.Id == shift.CompanyId)) //{ // return Tuple.Create(-1, "No Company exists with the ID = " + shift.CompanyId); //} //if (ctx.WorkShiftSet.Any(c => c.isActive == true && shift.DriverId == c.DriverId)) //{ // return Tuple.Create(-1, "An active shift already exists"); //} shift.isActive = true; ctx.WorkShiftSet.Add(shift); ctx.SaveChanges(); return(Tuple.Create(shift.Id, "Success")); } catch (Exception ex) { return(Tuple.Create(-1, ex.Message)); } } }
public Tuple <int, string> StartBreak(Break newBreak) { using (HuboDbContext ctx = new HuboDbContext()) { try { if (!ctx.WorkShiftSet.Any(s => s.Id == newBreak.ShiftId)) { return(Tuple.Create(-1, "No Shift exists for ID = " + newBreak.ShiftId)); } if (ctx.BreakSet.Any(b => b.isActive == true && b.ShiftId == newBreak.ShiftId)) { return(Tuple.Create(-1, "A break is already active")); } newBreak.isActive = true; ctx.BreakSet.Add(newBreak); ctx.SaveChanges(); return(Tuple.Create(newBreak.Id, "Success")); } catch (Exception ex) { return(Tuple.Create(-1, ex.Message)); } } }
public Tuple <int, string> StartDriving(DrivingShift shift) { using (HuboDbContext ctx = new HuboDbContext()) { try { if (!ctx.WorkShiftSet.Any(s => s.Id == shift.ShiftId)) { return(Tuple.Create(-1, "No Shift exists with the ID = " + shift.ShiftId)); } if (!ctx.VehicleSet.Any(v => v.Id == shift.VehicleId)) { return(Tuple.Create(-1, "No Vehicle exists with the ID = " + shift.VehicleId)); } if (ctx.DrivingShiftSet.Any(d => d.isActive == true && shift.ShiftId == d.ShiftId)) { return(Tuple.Create(-1, "A driving shift is already active")); } shift.isActive = true; ctx.DrivingShiftSet.Add(shift); ctx.SaveChanges(); return(Tuple.Create(shift.Id, "Success")); } catch (Exception ex) { return(Tuple.Create(-1, ex.Message)); } } }
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> 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)); } } }
public Tuple <List <Vehicle>, string, int> GetVehiclesByDriver(int driverId) { List <Vehicle> listOfVehicles = new List <Vehicle>(); using (HuboDbContext ctx = new HuboDbContext()) { try { if (!ctx.DriverSet.Any(d => d.Id == driverId)) { return(Tuple.Create(listOfVehicles, "Company not found for corresponding ID : " + driverId.ToString(), -1)); } listOfVehicles = (from vehicle in ctx.VehicleSet join company in ctx.CompanySet on vehicle.CompanyId equals company.Id join driveCompany in ctx.DriverCompanySet on company.Id equals driveCompany.CompanyId where driveCompany.DriverId == driverId select vehicle).ToList <Vehicle>(); return(Tuple.Create(listOfVehicles, "success", 1)); } catch (Exception ex) { return(Tuple.Create(listOfVehicles, ex.Message, -1)); } } }
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 <List <DrivingShift>, string, int> GetDrivingShifts(int shiftId) { List <DrivingShift> listOfDrivingShifts = new List <DrivingShift>(); using (HuboDbContext ctx = new HuboDbContext()) { try { if (!ctx.WorkShiftSet.Any(s => s.Id == shiftId)) { return(Tuple.Create(listOfDrivingShifts, "No Shift exists with the ID = " + shiftId, -1)); } listOfDrivingShifts = (from b in ctx.DrivingShiftSet where b.ShiftId == shiftId select b).ToList <DrivingShift>(); return(Tuple.Create(listOfDrivingShifts, "Success", 1)); } catch (Exception ex) { return(Tuple.Create(listOfDrivingShifts, ex.Message, -1)); } } }
//NOTE: For driveShift id //public Tuple<List<Break>, string, int> GetBreaks(int shiftId) //{ // using (HuboDbContext ctx = new HuboDbContext()) // { // List<Break> listOfBreaks = new List<Break>(); // try // { // if(!ctx.DrivingShiftSet.Any(s => s.Id == shiftId)) // { // return Tuple.Create(listOfBreaks, "No Shift exists with ID = " + shiftId, -1); // } // listOfBreaks = (from b in ctx.BreakSet // where b.ShiftId == shiftId // select b).ToList<Break>(); // return Tuple.Create(listOfBreaks, "Success", 1); // } // catch(Exception ex) // { // return Tuple.Create(listOfBreaks, ex.Message, -1); // } // } //} public Tuple <List <Break>, string, int> GetBreaks(int shiftId) { using (HuboDbContext ctx = new HuboDbContext()) { List <Break> listOfBreaks = new List <Break>(); try { if (!ctx.WorkShiftSet.Any <WorkShift>(d => d.Id == shiftId)) { return(Tuple.Create(listOfBreaks, "No Shift exists with ID = " + shiftId, -1)); } listOfBreaks = (from breaks in ctx.BreakSet join shift in ctx.WorkShiftSet on breaks.ShiftId equals shift.Id where shift.Id == shiftId select breaks).ToList <Break>(); return(Tuple.Create(listOfBreaks, "Success", 1)); } catch (Exception ex) { return(Tuple.Create(listOfBreaks, ex.Message, -1)); } } }
private bool checkUserEmail(string email, HuboDbContext ctx) { User user = new User(); user.EmailAddress = email; //ctx.UserSet.Add(user); /* * try * { * bool result = false; * // check licence number doesn't already exist * if (ctx.UserSet.Any(o => o.EmailAddress == user.EmailAddress)) * { * // Match! * result = true; * } * * return result; * } * catch (Exception ex) * { * string x = ex.Message; * * return false; * } */ return(false); }
public Tuple <List <WorkShift>, string, int> GetWorkShifts(int driverId) { List <WorkShift> listOfWorkShifts = new List <WorkShift>(); using (HuboDbContext ctx = new HuboDbContext()) { try { if (!ctx.DriverSet.Any(d => d.Id == driverId)) { return(Tuple.Create(listOfWorkShifts, "No Driver exists with Driver ID = " + driverId, -1)); } DateTime twoWeeksPrior = new DateTime(); twoWeeksPrior = DateTime.Now; twoWeeksPrior = twoWeeksPrior.AddDays(-14); //listOfWorkShifts = (from b in ctx.WorkShiftSet // where b.DriverId == driverId && // b.StartDate > twoWeeksPrior // select b).ToList<WorkShift>(); return(Tuple.Create(listOfWorkShifts, "Success", 1)); } catch (Exception ex) { return(Tuple.Create(listOfWorkShifts, ex.Message, -1)); } } }
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 WorkShift GetWorkShift(int workShiftId) { using (HuboDbContext ctx = new HuboDbContext()) { WorkShift currentShift = (from workShift in ctx.WorkShiftSet where workShift.Id == workShiftId select workShift).FirstOrDefault <WorkShift>(); return(currentShift); } }
public List <Break> GetBreaksList(int shiftId) { using (HuboDbContext ctx = new HuboDbContext()) { List <Break> listOfBreaks = new List <Break>(); listOfBreaks = (from breaks in ctx.BreakSet join shift in ctx.WorkShiftSet on breaks.ShiftId equals shift.Id where shift.Id == shiftId select breaks).ToList <Break>(); return(listOfBreaks); } }
public List <DrivingShift> GetDrivingShiftsWorkId(int workShiftId) { using (HuboDbContext ctx = new HuboDbContext()) { List <DrivingShift> listOfDrivingShifts = (from d in ctx.DrivingShiftSet where d.ShiftId == workShiftId orderby d.StartDrivingDateTime descending select d).ToList <DrivingShift>(); return(listOfDrivingShifts); } }
public int GetAmountOfShifts(int workShiftId) { using (HuboDbContext ctx = new HuboDbContext()) { var dayShiftId = (from w in ctx.WorkShiftSet where workShiftId == w.Id select w.DayShiftId).Single(); List <WorkShift> listOfCurrentWorkShifts = (from w in ctx.WorkShiftSet where dayShiftId == w.DayShiftId select w).ToList <WorkShift>(); return(listOfCurrentWorkShifts.Count); } }
//public List<WorkShift> GetShiftFromLastLongBreak(int driverId) //{ // List<WorkShift> listOfWorkShifts = new List<WorkShift>(); // using (HuboDbContext ctx = new HuboDbContext()) // { // try // { // WorkShift lastWorkShift = ctx.WorkShiftSet.Where(p => p.TimeSinceLastShiftMins >= 1440 && p.DriverId == driverId).OrderByDescending(p => p.Id).First(); // listOfWorkShifts = ctx.WorkShiftSet.Where(p => p.DriverId == driverId && p.StartDate >= lastWorkShift.StartDate).ToList<WorkShift>(); // return listOfWorkShifts; // } // catch (Exception ex) // { // return listOfWorkShifts; // } // } //} public long GetDriverId(long id) { using (HuboDbContext ctx = new HuboDbContext()) { try { Driver driver = ctx.DriverSet.Single <Driver>(d => d.UserId == id); return(driver.Id); } catch { return(0); } } }
public User GetUserDetails(string usernameOrEmailAddress) { using (HuboDbContext ctx = new HuboDbContext()) { try { User test = ctx.Users.Single <User>(b => b.EmailAddress == usernameOrEmailAddress); return(test); } catch (Exception ex) { return(null); } } }
public Tuple <Driver, int, string> GetDriverDetails(int userId) { Driver currentDriver = new Driver(); using (HuboDbContext ctx = new HuboDbContext()) { try { currentDriver = ctx.DriverSet.Single <Driver>(d => d.UserId == userId); return(Tuple.Create(currentDriver, 1, "Success")); } catch (Exception ex) { return(Tuple.Create(currentDriver, -1, ex.Message)); } } }
public List <Break> GetBreaks(List <long> listOfWorkShiftIds) { List <Break> listOfBreaks = new List <Break>(); using (HuboDbContext ctx = new HuboDbContext()) { try { listOfBreaks = ctx.BreakSet.Where(c => listOfWorkShiftIds.Contains(c.ShiftId)).ToList <Break>(); return(listOfBreaks); } catch (Exception ex) { return(listOfBreaks); } } }
public List <DrivingShift> GetDrivingShifts(List <long> listOfWorkShiftIds) { List <DrivingShift> listOfDrivingShifts = new List <DrivingShift>(); using (HuboDbContext ctx = new HuboDbContext()) { try { listOfDrivingShifts = ctx.DrivingShiftSet.Where(c => listOfWorkShiftIds.Contains(c.ShiftId)).ToList <DrivingShift>(); return(listOfDrivingShifts); } catch (Exception ex) { return(listOfDrivingShifts); } } }
public Tuple <List <Vehicle>, string, int> GetVehicles(List <long> listCompanyIds) { List <Vehicle> listOfVehicles = new List <Vehicle>(); using (HuboDbContext ctx = new HuboDbContext()) { try { listOfVehicles = ctx.VehicleSet.Where(t => listCompanyIds.Contains(t.CompanyId)).ToList <Vehicle>(); return(Tuple.Create(listOfVehicles, "Success", 1)); } catch (Exception ex) { return(Tuple.Create(listOfVehicles, ex.Message, -1)); } } }
public List <Note> GetNotes(List <long> listOfWorkShiftIds) { List <Note> listOfNotes = new List <Note>(); using (HuboDbContext ctx = new HuboDbContext()) { try { listOfNotes = ctx.NoteSet.Where(c => listOfWorkShiftIds.Contains(c.ShiftId)).ToList <Note>(); return(listOfNotes); } catch (Exception ex) { return(listOfNotes); } } }
public int RegisterDriver(Driver driver) { using (HuboDbContext ctx = new HuboDbContext()) { //ctx.DriverSet.Add(driver); //// functionality of this code should be to check if email exists in User table and if not create the user //// then save driver as Driver using the created user ID //bool userExists = checkUserEmail(driver.Email, ctx); //// if user doesn't exist need to register them first then go on to save them as a driver //if(!userExists) //{ // // createUser(); //} //else //{ // //Matching User was found, thus email is in use, thus invalid // return -1; //} //try //{ // int result = 0; // // check licence number doesn't already exist // if (ctx.DriversSet.Any(o => o.LicenceNo == driver.LicenceNo)) // { // // Match! // result = -1; // } else // { // result = ctx.SaveChanges(); // } // return result; //} //catch (Exception ex) { // string x = ex.Message; // return 0; //} } return(0); }
public List <Licence> GetLicences(int driverId) { List <Licence> listOfLicences = new List <Licence>(); using (HuboDbContext ctx = new HuboDbContext()) { try { listOfLicences = (from licences in ctx.LicenceSet where licences.DriverId == driverId select licences).ToList <Licence>(); return(listOfLicences); } catch (Exception ex) { return(listOfLicences); } } }
public Tuple <int, string> InsertNote(Note note) { using (HuboDbContext ctx = new HuboDbContext()) { try { if (!ctx.WorkShiftSet.Any(s => s.Id == note.ShiftId)) { return(Tuple.Create(-1, "No Shift exists with the ID = " + note.ShiftId)); } ctx.NoteSet.Add(note); ctx.SaveChanges(); return(Tuple.Create(note.Id, "Success")); } catch (Exception ex) { return(Tuple.Create(-1, ex.Message)); } } }
public Tuple <int, string, int> GetVehicleHubo(int vehicleId) { int hubo = 0; using (HuboDbContext ctx = new HuboDbContext()) { try { if (!ctx.VehicleSet.Any(v => v.Id == vehicleId)) { return(Tuple.Create(hubo, "No vehicle exists with ID = " + vehicleId, -1)); } List <DrivingShift> vehicleDrives = (from b in ctx.DrivingShiftSet where b.VehicleId == vehicleId select b).ToList <DrivingShift>(); if (vehicleDrives.Count == 0) { return(Tuple.Create(0, "Success", 1)); } DrivingShift lastDrive = new DrivingShift(); lastDrive.StopDrivingDateTime = vehicleDrives[0].StopDrivingDateTime; foreach (DrivingShift drive in vehicleDrives) { if (drive.StopDrivingDateTime > lastDrive.StopDrivingDateTime) { lastDrive = drive; } } return(Tuple.Create(lastDrive.StopHubo, "success", 1)); } catch (Exception ex) { return(Tuple.Create(hubo, ex.Message, -1)); } } }
public Tuple <List <Company>, string, int> GetCompanyList(int driverId) { List <Company> listOfCompanies = new List <Company>(); using (HuboDbContext ctx = new HuboDbContext()) { try { if (!ctx.DriverSet.Any(d => d.Id == driverId)) { return(Tuple.Create(listOfCompanies, "No Driver found with corresponding ID = " + driverId.ToString(), -1)); } List <DriverCompany> driverCompanies = (from b in ctx.DriverCompanySet where b.DriverId.Equals(driverId) select b).ToList <DriverCompany>(); foreach (DriverCompany driverCompany in driverCompanies) { Company tempCompany = ctx.CompanySet.Single <Company>(c => c.Id == driverCompany.CompanyId); listOfCompanies.Add(tempCompany); } if (listOfCompanies.Count == 0) { return(Tuple.Create(listOfCompanies, "No Companies found for Driver ID = " + driverId.ToString(), -1)); } return(Tuple.Create(listOfCompanies, "Success", 1)); } catch (Exception ex) { return(Tuple.Create(listOfCompanies, ex.Message, -1)); } } }
public Tuple <int, string> InsertGeoData(List <GeoData> geoData) { using (HuboDbContext ctx = new HuboDbContext()) { try { foreach (GeoData geoInsert in geoData) { if (!ctx.DrivingShiftSet.Any(d => d.Id == geoInsert.DrivingShiftId)) { return(Tuple.Create(-1, "No Driving Shift exists with ID : " + geoInsert.DrivingShiftId)); } ctx.GeoDataSet.Add(geoInsert); } ctx.SaveChanges(); return(Tuple.Create(1, "Success")); } catch (Exception ex) { return(Tuple.Create(-1, ex.Message)); } } }
public Tuple <int, string> StartDay(int driverId) { //Get all workshifts with driverid using (HuboDbContext ctx = new HuboDbContext()) { try { if (!ctx.DriverSet.Any(d => d.Id == driverId)) { return(Tuple.Create(-1, "No Driver exists with Driver ID = " + driverId)); } //DateTime twoWeeksPrior = default(DateTime); //twoWeeksPrior = DateTime.Now; //twoWeeksPrior = twoWeeksPrior.AddDays(-14); //List<long> listOfDayIds = (from b in ctx.WorkShiftSet // where b.DriverId == driverId && // b.StartDate > twoWeeksPrior // orderby b.DayShiftId descending // select b.DayShiftId).ToList<long>(); //if (listOfDayIds.Count == 0) //{ // // Start new day // DayShift newDayShift = new DayShift(); // ctx.DayShiftSet.Add(newDayShift); // ctx.SaveChanges(); // return Tuple.Create(newDayShift.Id, "Success"); //} //else //{ // // Check if need to send this id, or need to create a new one // long workingDayShiftId = listOfDayIds[0]; // List<WorkShift> listOfWorkShifts = (from b in ctx.WorkShiftSet // where b.DayShiftId == workingDayShiftId // orderby b.StartDate ascending // select b).ToList<WorkShift>(); // WorkShift firstShiftOfTheDay = listOfWorkShifts[0]; // if (firstShiftOfTheDay.StartDate.Value.AddHours(14) > DateTime.Now) // { // // No starting new workday yet // return Tuple.Create(Convert.ToInt32(workingDayShiftId), "Success"); // } // else // { // // New work date // DayShift newDayShift = new DayShift(); // ctx.DayShiftSet.Add(newDayShift); // ctx.SaveChanges(); // return Tuple.Create(newDayShift.Id, "Success"); // } //} DayShift newDayShift = new DayShift(); ctx.DayShiftSet.Add(newDayShift); ctx.SaveChanges(); return(Tuple.Create(newDayShift.Id, "Success")); } catch (Exception ex) { return(Tuple.Create(-1, ex.Message)); } } }