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> 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));
                }
            }
        }
예제 #3
0
        private AjaxResponse StopDriving(DrivingShift shift)
        {
            AjaxResponse        ar     = new AjaxResponse();
            Tuple <int, string> result = _drivingShiftAppService.StopDriving(shift);

            if (result.Item1 == -1)
            {
                ar.Success = false;
                ar.Result  = result.Item2;
            }
            else
            {
                ar.Success = true;
                ar.Result  = result.Item1;
            }

            return(ar);
        }
예제 #4
0
        private AjaxResponse StartDriving(DrivingShift shift)
        {
            AjaxResponse        ar     = new AjaxResponse();
            Tuple <int, string> result = _drivingShiftAppService.StartDriving(shift);

            //A valid ID was returned, thus successful
            if (result.Item1 > 0)
            {
                ar.Success = true;
                ar.Result  = result.Item1;
            }
            else
            {
                ar.Success = false;
                ar.Result  = result.Item2;
            }

            return(ar);
        }
        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));
                }
            }
        }
예제 #6
0
 public async Task <AjaxResponse> StartDrivingAsync([FromBody] DrivingShift shift)
 {
     return(await Task <AjaxResponse> .Run(() => StartDriving(shift)));
 }
 public Tuple <int, string> StopDriving(DrivingShift shift)
 {
     return(_drivingShiftRepository.StopDriving(shift));
 }