Example #1
0
 public ActionResult GetTripsWithFilter(string triptype, string vehicleno, DateTime?fromdate, DateTime?todate)
 {
     try
     {
         if (triptype != "Local" && triptype != "Line")
         {
             return(BadRequest(new ResponseData
             {
                 Code = "401",
                 Message = "Bad Request. Invalid trip type"
             }));
         }
         if (vehicleno == null && fromdate == null && todate == null)
         {
             var getTrips = MH.GetListOfObjects(tripinfo_collection, "TripType", triptype, null, null).Result;
             if (getTrips != null)
             {
                 List <TripInfo> tripInfo    = new List <TripInfo>();
                 var             currentDate = DateTime.Now;
                 List <DateTime> dateList    = GH.GetDateRange(DateTime.UtcNow.AddDays(-2).Date, DateTime.UtcNow.Date);
                 foreach (var trip in getTrips)
                 {
                     var tripData = BsonSerializer.Deserialize <TripInfo>(trip);
                     if (tripData.LoadDate != null && dateList.Contains(tripData.LoadDate.Value.Date))
                     {
                         tripInfo.Add(tripData);
                     }
                 }
                 var sortedList = tripInfo.OrderBy(o => o.LoadDate).ToList();
                 if (tripInfo.Count == 0)
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "404",
                         Message = "No trips found"
                     }));
                 }
                 else
                 {
                     return(Ok(new ResponseData
                     {
                         Code = "200",
                         Message = "Success",
                         Data = sortedList
                     }));
                 }
             }
             else
             {
                 return(BadRequest(new ResponseData
                 {
                     Code = "404",
                     Message = "No trips found"
                 }));
             }
         }
         else
         {
             if (vehicleno != null)
             {
                 var getTripsWithVehicleNo = MH.GetListOfObjects(tripinfo_collection, "VehicleNo", vehicleno, "TripType", triptype).Result;
                 if (fromdate == null && todate == null)
                 {
                     var date = DateTime.UtcNow.Date;
                     if (getTripsWithVehicleNo != null)
                     {
                         List <TripInfo> tripInfo = new List <TripInfo>();
                         foreach (var trip in getTripsWithVehicleNo)
                         {
                             tripInfo.Add(BsonSerializer.Deserialize <TripInfo>(trip));
                         }
                         var sortedList = tripInfo.OrderBy(o => o.LoadDate).ToList();
                         return(Ok(new ResponseData
                         {
                             Code = "200",
                             Message = "Success",
                             Data = sortedList
                         }));
                     }
                     else
                     {
                         return(BadRequest(new ResponseData
                         {
                             Code = "404",
                             Message = "No trips found"
                         }));
                     }
                 }
                 else if (fromdate != null && todate == null)
                 {
                     var             dateList = GH.GetDateRange(fromdate.Value.Date, DateTime.UtcNow.AddDays(1).Date);
                     List <TripInfo> tripList = new List <TripInfo>();
                     foreach (var trip in getTripsWithVehicleNo)
                     {
                         var tripData = BsonSerializer.Deserialize <TripInfo>(trip);
                         if (tripData.LoadDate != null && dateList.Contains(tripData.LoadDate.Value.Date))
                         {
                             tripList.Add(tripData);
                         }
                     }
                     if (tripList.Count == 0)
                     {
                         {
                             return(BadRequest(new ResponseData
                             {
                                 Code = "404",
                                 Message = "No trips found"
                             }));
                         }
                     }
                     else
                     {
                         var sortedList = tripList.OrderBy(o => o.LoadDate).ToList();
                         return(Ok(new ResponseData
                         {
                             Code = "200",
                             Message = "Success",
                             Data = sortedList
                         }));
                     }
                 }
                 else if (fromdate == null && todate != null)
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "400",
                         Message = "Bad Request"
                     }));
                 }
                 else
                 {
                     var             dateList = GH.GetDateRange(fromdate.Value.Date, todate.Value.AddDays(1).Date);
                     List <TripInfo> tripList = new List <TripInfo>();
                     foreach (var trip in getTripsWithVehicleNo)
                     {
                         var tripData = BsonSerializer.Deserialize <TripInfo>(trip);
                         if (tripData.LoadDate != null && dateList.Contains(tripData.LoadDate.Value.Date))
                         {
                             tripList.Add(tripData);
                         }
                     }
                     if (tripList.Count == 0)
                     {
                         {
                             return(BadRequest(new ResponseData
                             {
                                 Code = "404",
                                 Message = "No trips found"
                             }));
                         }
                     }
                     else
                     {
                         var sortedList = tripList.OrderBy(o => o.LoadDate).ToList();
                         return(Ok(new ResponseData
                         {
                             Code = "200",
                             Message = "Success",
                             Data = sortedList
                         }));
                     }
                 }
             }
             else
             {
                 var getTripsWithOutVehicleNo = MH.GetListOfObjects(tripinfo_collection, "TripType", triptype, null, null).Result;
                 if (fromdate != null && todate == null)
                 {
                     var             dateList = GH.GetDateRange(fromdate.Value.Date, DateTime.UtcNow.AddDays(1).Date);
                     List <TripInfo> tripList = new List <TripInfo>();
                     foreach (var trip in getTripsWithOutVehicleNo)
                     {
                         var tripData = BsonSerializer.Deserialize <TripInfo>(trip);
                         if (tripData.LoadDate != null && dateList.Contains(tripData.LoadDate.Value.Date))
                         {
                             tripList.Add(tripData);
                         }
                     }
                     if (tripList.Count == 0)
                     {
                         {
                             return(BadRequest(new ResponseData
                             {
                                 Code = "404",
                                 Message = "No trips found"
                             }));
                         }
                     }
                     else
                     {
                         var sortedList = tripList.OrderBy(o => o.LoadDate).ToList();
                         return(Ok(new ResponseData
                         {
                             Code = "200",
                             Message = "Success",
                             Data = sortedList
                         }));
                     }
                 }
                 else if (fromdate == null && todate != null)
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "400",
                         Message = "Bad Request"
                     }));
                 }
                 else
                 {
                     var             dateList = GH.GetDateRange(fromdate.Value.Date, todate.Value.AddDays(1).Date);
                     List <TripInfo> tripList = new List <TripInfo>();
                     foreach (var trip in getTripsWithOutVehicleNo)
                     {
                         var tripData = BsonSerializer.Deserialize <TripInfo>(trip);
                         if (tripData.LoadDate != null && dateList.Contains(tripData.LoadDate.Value.Date))
                         {
                             tripList.Add(tripData);
                         }
                     }
                     if (tripList.Count == 0)
                     {
                         {
                             return(BadRequest(new ResponseData
                             {
                                 Code = "404",
                                 Message = "No trips found"
                             }));
                         }
                     }
                     else
                     {
                         var sortedList = tripList.OrderBy(o => o.LoadDate).ToList();
                         return(Ok(new ResponseData
                         {
                             Code = "200",
                             Message = "Success",
                             Data = sortedList
                         }));
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TripController", "GetTripsWithFilter", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Example #2
0
 public ActionResult GetTripInfoWithUnPaidBalanceAmountWithFliter(DateTime?fromdate, DateTime?todate)
 {
     try
     {
         List <TripInfo> tripDetailsList = new List <TripInfo>();
         var             getTrips        = MH.GetListOfObjects(tripinfo_collection, null, null, null, null).Result;
         if (getTrips == null)
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No trips found"
             }));
         }
         else
         {
             foreach (var trip in getTrips)
             {
                 var deserlizedData = BsonSerializer.Deserialize <TripInfo>(trip);
                 if (deserlizedData.BalanceAmount > 0)
                 {
                     tripDetailsList.Add(deserlizedData);
                 }
             }
         }
         if (fromdate != null && todate == null)
         {
             var             dateList = GH.GetDateRange(fromdate.Value.Date, DateTime.UtcNow.AddDays(1).Date);
             List <TripInfo> tripList = new List <TripInfo>();
             foreach (var trip in tripDetailsList)
             {
                 if (trip.LoadDate != null && dateList.Contains(trip.LoadDate.Value.Date))
                 {
                     tripList.Add(trip);
                 }
             }
             if (tripList.Count == 0)
             {
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "404",
                         Message = "No trips found"
                     }));
                 }
             }
             else
             {
                 var sortedList = tripList.OrderBy(o => o.LoadDate).ToList();
                 return(Ok(new ResponseData
                 {
                     Code = "200",
                     Message = "Success",
                     Data = sortedList
                 }));
             }
         }
         else if (fromdate == null && todate == null)
         {
             var sortedList = tripDetailsList.OrderBy(o => o.LoadDate).ToList();
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = sortedList
             }));
         }
         else if (fromdate == null && todate != null)
         {
             return(BadRequest(new ResponseData
             {
                 Code = "400",
                 Message = "Bad Request"
             }));
         }
         else
         {
             var             dateList = GH.GetDateRange(fromdate.Value.Date, todate.Value.AddDays(1).Date);
             List <TripInfo> tripList = new List <TripInfo>();
             foreach (var trip in tripDetailsList)
             {
                 if (trip.LoadDate != null && dateList.Contains(trip.LoadDate.Value.Date))
                 {
                     tripList.Add(trip);
                 }
             }
             if (tripList.Count == 0)
             {
                 {
                     return(BadRequest(new ResponseData
                     {
                         Code = "404",
                         Message = "No trips found"
                     }));
                 }
             }
             else
             {
                 var sortedList = tripList.OrderBy(o => o.LoadDate).ToList();
                 return(Ok(new ResponseData
                 {
                     Code = "200",
                     Message = "Success",
                     Data = sortedList
                 }));
             }
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("TripController", "GetTripInfoWithUnPaidBalanceAmountWithFliter", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }
Example #3
0
 public ActionResult NotificationForRenewal()
 {
     try
     {
         var getVehicles = MH.GetListOfObjects(vehicleinfo_collection, null, null, null, null).Result;
         if (getVehicles != null)
         {
             List <RenewalDetails> insuranceRenewalList = new List <RenewalDetails>();
             List <RenewalDetails> fcRenewalList        = new List <RenewalDetails>();
             List <RenewalDetails> npTaxRenewalList     = new List <RenewalDetails>();
             List <RenewalDetails> permitRenewalList    = new List <RenewalDetails>();
             var currentDate = DateTime.UtcNow.Date;
             var dateList    = GH.GetDateRange(currentDate.Date, currentDate.AddDays(20).Date);
             foreach (var vehicle in getVehicles)
             {
                 var vehicleData = BsonSerializer.Deserialize <VehicleInfo>(vehicle);
                 if (vehicleData.InsuranceDate != null)
                 {
                     if (vehicleData.InsuranceDate < currentDate || dateList.Contains(vehicleData.InsuranceDate.Value.Date))
                     {
                         insuranceRenewalList.Add(new RenewalDetails {
                             VehicleNo = vehicleData.VehicleNo, Date = vehicleData.InsuranceDate.Value.Date
                         });
                     }
                 }
                 if (vehicleData.FCDate != null)
                 {
                     if (vehicleData.FCDate < currentDate || dateList.Contains(vehicleData.FCDate.Value.Date))
                     {
                         fcRenewalList.Add(new RenewalDetails {
                             VehicleNo = vehicleData.VehicleNo, Date = vehicleData.FCDate.Value.Date
                         });
                     }
                 }
                 if (vehicleData.NPTaxDate != null)
                 {
                     if (vehicleData.NPTaxDate < currentDate || dateList.Contains(vehicleData.NPTaxDate.Value.Date))
                     {
                         npTaxRenewalList.Add(new RenewalDetails {
                             VehicleNo = vehicleData.VehicleNo, Date = vehicleData.NPTaxDate.Value.Date
                         });
                     }
                 }
                 if (vehicleData.PermitDate != null)
                 {
                     if (vehicleData.PermitDate < currentDate || dateList.Contains(vehicleData.PermitDate.Value.Date))
                     {
                         permitRenewalList.Add(new RenewalDetails {
                             VehicleNo = vehicleData.VehicleNo, Date = vehicleData.PermitDate.Value.Date
                         });
                     }
                 }
             }
             List <RenewalDetails> sortedInsuranceRenewalList = new List <RenewalDetails>();
             List <RenewalDetails> sortedFCRenewalList        = new List <RenewalDetails>();
             List <RenewalDetails> sortedNPTaxRenewalList     = new List <RenewalDetails>();
             List <RenewalDetails> sortedPermitRenewalList    = new List <RenewalDetails>();
             if (insuranceRenewalList != null)
             {
                 sortedInsuranceRenewalList = insuranceRenewalList.OrderBy(o => o.Date).ToList();
             }
             if (fcRenewalList != null)
             {
                 sortedFCRenewalList = fcRenewalList.OrderBy(o => o.Date).ToList();
             }
             if (npTaxRenewalList != null)
             {
                 sortedNPTaxRenewalList = npTaxRenewalList.OrderBy(o => o.Date).ToList();
             }
             if (permitRenewalList != null)
             {
                 sortedPermitRenewalList = permitRenewalList.OrderBy(o => o.Date).ToList();
             }
             RenewalList renewalDateDetails = new RenewalList
             {
                 InsuranceRenewalList = sortedInsuranceRenewalList,
                 FCRenewalList        = sortedFCRenewalList,
                 NPTaxRenewalList     = sortedNPTaxRenewalList,
                 PermitRenewlList     = sortedPermitRenewalList
             };
             return(Ok(new ResponseData
             {
                 Code = "200",
                 Message = "Success",
                 Data = renewalDateDetails
             }));
         }
         else
         {
             return(BadRequest(new ResponseData
             {
                 Code = "404",
                 Message = "No vehicles found"
             }));
         }
     }
     catch (Exception ex)
     {
         SL.CreateLog("VehicleController", "GetInfoOfVehicle", ex.Message);
         return(BadRequest(new ResponseData
         {
             Code = "400",
             Message = "Failed",
             Data = ex.Message
         }));
     }
 }