Пример #1
0
 public int?GetLastVehicalOpenTrip(string vId)
 {
     using (VehicleStatusRepository vsRepo = new VehicleStatusRepository())
     {
         VehicleStatus vsModel = vsRepo.GetByQR(vId);
         if (vsModel != null)
         {
             return(_objectSet.FirstOrDefault(x => x.VehicleId == vsModel.VehicleId && x.IsDone == false)?.Id);
         }
     }
     return(null);
 }
Пример #2
0
        public RequestResponse UpdateTripRate(int tripId, int rate, bool isRepair)
        {
            Trips currentTrip = GetById(tripId);

            currentTrip.Rate = byte.Parse(rate.ToString());
            AddUpdate(currentTrip);

            if (isRepair)
            {
                using (VehicleStatusRepository vStatus = new VehicleStatusRepository())
                {
                    VehicleStatus currentVStatusModel = vStatus.GetById(currentTrip.VehicleId);
                    currentVStatusModel.InService = isRepair;

                    vStatus.AddUpdate(currentVStatusModel);
                }
            }
            return(responseObj);
        }
Пример #3
0
        public RequestResponse TripRegister(VehicaleReservationModel data)
        {
            Trips tripModel = new Trips()
            {
                VehicleId = int.Parse(data.vehicleId),
                RiderId   = data.riderId
            };

            switch (data.reservationEnum)
            {
            case TripType.Start:

                // check if v QR found
                using (VehicleRepository vRepo = new VehicleRepository())
                {
                    if (!vRepo.IsAvilableByBarcode(data.qrStr, int.Parse(data.vehicleId)))
                    {
                        responseObj.ErrorMessages.Add("nodata", "QR is wrong");
                        return(responseObj);
                    }
                }

                //if (!data.tripId.HasValue)
                //{
                //    responseObj.ErrorMessages.Add("tripId", OperationLP.InvalidData);
                //}
                //else
                //{
                //tripModel = GetById(data.tripId.Value);
                tripModel.CreatedDate = DateTime.Now;
                tripModel.StartTime   = DateTime.Now;
                tripModel.TempRequest = false;
                responseObj           = AddUpdate(tripModel);

                using (VehicleStatusRepository vsRepo = new VehicleStatusRepository())
                {
                    vsRepo.UpdateInRide(int.Parse(data.vehicleId));
                }
                //}
                break;

            case TripType.End:
                if (!data.tripId.HasValue)
                {
                    responseObj.ErrorMessages.Add("tripId", OperationLP.InvalidData);
                }
                else
                {
                    tripModel         = GetById(data.tripId.Value);
                    tripModel.EndTime = DateTime.Now;
                    tripModel.IsDone  = true;
                    TimeSpan span          = DateTime.Parse(tripModel.EndTime.ToString()) - DateTime.Parse(tripModel.StartTime.ToString());
                    double   totalMinutes  = span.TotalMinutes;
                    double   totalHours    = span.TotalHours;
                    double   totalSecounds = span.TotalSeconds;

                    //tripModel.Duration = string.Format("{0}:{1}:{2}", totalHours, totalMinutes, totalSecounds);
                    tripModel.Duration = Math.Round(totalMinutes, 2).ToString();

                    double unloackAmount = double.Parse(System.Configuration.ConfigurationManager.AppSettings["unlockAmount"].ToString());
                    double minuteAmount  = double.Parse(System.Configuration.ConfigurationManager.AppSettings["minuteAmount"].ToString());


                    decimal totalAmount = Math.Round(decimal.Parse((unloackAmount + (totalMinutes * minuteAmount)).ToString()), 2);
                    tripModel.Amount = totalAmount;

                    if (data.PromoCodeId > 0)
                    {
                        decimal promoDiscount = 0;
                        using (PromoCodeRepository promoRepo = new PromoCodeRepository())
                        {
                            PromoCode promoModel = promoRepo.GetById(data.PromoCodeId);
                            if (promoModel != null)
                            {
                                promoDiscount = promoModel.Percentage;
                            }
                        }
                        tripModel.NetAmount = totalAmount - ((totalAmount * promoDiscount) / 100);
                    }
                    else
                    {
                        tripModel.NetAmount = totalAmount;
                    }


                    responseObj = AddUpdate(tripModel);

                    using (VehicleStatusRepository vsRepo = new VehicleStatusRepository())
                    {
                        vsRepo.UpdateInRide(int.Parse(data.vehicleId), false, data.needPrepare);
                    }
                }
                break;

            case TripType.TempRequest:
                tripModel.CreatedDate = DateTime.Now;
                tripModel.TempRequest = true;
                responseObj           = AddUpdate(tripModel);
                break;

            case TripType.Cancel:
                if (!data.tripId.HasValue)
                {
                    responseObj.ErrorMessages.Add("tripId", OperationLP.InvalidData);
                }
                else
                {
                    tripModel          = GetById(data.tripId.Value);
                    tripModel.IsDone   = false;
                    tripModel.IsCancel = true;
                    responseObj        = AddUpdate(tripModel);
                }
                break;

            default:
                break;
            }
            return(responseObj);
        }
Пример #4
0
        public override RequestResponse AddUpdate(Vehicles entity)
        {
            Validate(entity);

            if (responseObj.ErrorMessages.Count <= 0)
            {
                if (entity.Id > 0)
                {
                    using (VehicleStatusRepository vStatusRepo = new VehicleStatusRepository())
                    {
                        vStatusRepo.AddUpdate(new VehicleStatus()
                        {
                            AreaId        = entity.VehicleStatus.AreaId,
                            BatteryStatus = entity.VehicleStatus.BatteryStatus,
                            InRide        = entity.VehicleStatus.InRide,
                            InService     = entity.VehicleStatus.InService,
                            LatV          = entity.VehicleStatus.LatV,
                            LongV         = entity.VehicleStatus.LongV,
                            VehicleId     = entity.VehicleStatus.VehicleId,
                            VehicleQR     = entity.VehicleStatus.VehicleQR
                        });

                        vStatusRepo.Save();
                    }

                    using (VehicleSpecsRepository vSpecsRepo = new VehicleSpecsRepository())
                    {
                        vSpecsRepo.AddUpdate(new VehicleSpecs()
                        {
                            VehicleId  = entity.VehicleSpecs.VehicleId,
                            CategoryId = entity.VehicleSpecs.CategoryId,
                            ModelId    = entity.VehicleSpecs.ModelId
                        });

                        vSpecsRepo.Save();
                    }

                    Attach(new Vehicles()
                    {
                        Id        = entity.Id,
                        Name      = entity.Name,
                        PlateNo   = entity.PlateNo,
                        HolderId  = entity.HolderId,
                        IsActive  = entity.IsActive,
                        UniqueId  = entity.UniqueId,
                        ImageName = entity.ImageName
                    });
                }
                else
                {
                    // Generate QR
                    entity.UniqueId  = RandomNumber(10);
                    entity.ImageName = string.IsNullOrEmpty(entity.ImageName) ? "noimage" : entity.ImageName;
                    entity.VehicleStatus.VehicleQR = entity.UniqueId;
                    Add(entity);
                }
                Save();
                responseObj.Messages.Add("succss", OperationLP.SuccessMsg);
            }
            return(responseObj);
        }