예제 #1
0
        public ActionResult BataEditorUpdate(TripViewModel model)
        {
            try
            {
                if (model.AdditionalAmount != 0)
                {
                    CustomBata retrieveBata = _custombataService.RetrieveCustomBataByTripId(model.TripId);
                    if (retrieveBata != null)
                    {
                        retrieveBata.TripId       = model.TripId;
                        retrieveBata.CustomAmount = model.AdditionalAmount;
                        retrieveBata.IsDeleted    = false;
                        _custombataService.SaveCustomBataData(retrieveBata);
                    }
                    else
                    {
                        CustomBata customBata = new CustomBata()
                        {
                            TripId       = model.TripId,
                            CustomAmount = model.AdditionalAmount
                        };
                        _custombataService.SaveCustomBataData(customBata);
                    }
                }
                if (model.BataRateId != 0)
                {
                    if (model.BataIdOld != model.BataRateId)
                    {
                        if (!_tripBataService.IsBattaNotExists(model.TripId))
                        {
                            _tripBataService.RemoveBata(model.TripId);

                            BataRate bataRate = _bataRateService.GetBataRateById(model.BataRateId);
                            if (bataRate != null)
                            {
                                TripBata bataDetails = new TripBata()
                                {
                                    TripId      = model.TripId,
                                    Description = bataRate.Description,
                                    Amount      = bataRate.Amount,
                                    IsDeleted   = false
                                };
                                _tripBataService.SaveBataData(bataDetails);
                            }
                        }
                        else
                        {
                            BataRate bataRate = _bataRateService.GetBataRateById(model.BataRateId);
                            if (bataRate != null)
                            {
                                TripBata bataDetails = new TripBata()
                                {
                                    TripId      = model.TripId,
                                    Description = bataRate.Description,
                                    Amount      = bataRate.Amount,
                                    IsDeleted   = false
                                };
                                _tripBataService.SaveBataData(bataDetails);
                            }
                        }
                    }
                }
                else
                {
                    if (!_tripBataService.IsBattaNotExists(model.TripId))
                    {
                        _tripBataService.RemoveBata(model.TripId);
                    }
                }
                _tripService.UpdatePendingTrip(model.TripId);
                return(RedirectToAction("BataEditorTripIndex", "Trips"));
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
 public void SaveBataData(TripBata bataDetails)
 {
     _tripBataRepository.SaveBataData(bataDetails);
 }
예제 #3
0
        public async Task <ActionResult> Edit(TripViewModel model)
        {
            try
            {
                string DispatcherName = System.Web.HttpContext.Current.User.Identity.Name;
                string message        = "";
                Trip   trip           = new Trip();
                if (model.VehicleId != 0)
                {
                    if (model.DriverId != 0)
                    {
                        if (model.MeterReadingIn > 0)
                        {
                            if (model.BataRateId != 0)
                            {
                                BataRate bataRate = _bataRateService.GetBataRateById(model.BataRateId);
                                if (bataRate != null)
                                {
                                    TripBata bataDetails = new TripBata();
                                    bataDetails.TripId      = model.TripId;
                                    bataDetails.Description = bataRate.Description;
                                    bataDetails.Amount      = bataRate.Amount;
                                    if (_tripBataService.IsBattaNotExists(model.TripId))
                                    {
                                        _tripBataService.SaveBataData(bataDetails);
                                    }
                                }
                            }

                            //update vehicle is available
                            List <int> vehicle = new List <int>()
                            {
                                model.VehicleId
                            };
                            await Task.Run(() => _vehicleService.UpdateVehicleAvailable(vehicle));

                            //update driver is available
                            List <int> driver = new List <int>()
                            {
                                model.DriverId
                            };
                            await Task.Run(() => _driverService.UpdateDriverAvailable(driver));

                            if (model != null)
                            {
                                trip             = AutoMapper.Mapper.Map <Trip>(model);
                                trip.Updatedby   = DispatcherName;
                                trip.TripMileage = (trip.MeterReadingIn - trip.MeterReadingOut);

                                if (model.PackageIds != null && model.PackageIds.Count() > 0)
                                {
                                    foreach (int pid in model.PackageIds)
                                    {
                                        PreDefineTrip predefTrip = _preDefineTripService.GetPreDefineTripById(pid);
                                        if (predefTrip != null)
                                        {
                                            PackagesList package = new PackagesList();
                                            package.TripId            = model.TripId;
                                            package.PreDefineTripName = predefTrip.PreDefineTripName;
                                            package.Rate = predefTrip.Rate;
                                            if (_packageListService.IsPackageExists(model.TripId, predefTrip.PreDefineTripName))
                                            {
                                                await Task.Run(() => _packageListService.SavePackage(package));
                                            }
                                        }
                                    }
                                }
                                //gps data collection
                                if (model.VehicleNumber != null)
                                {
                                    GpsVehicleDetailsDto gpsDetails = await _gpsClientService.GpsMeterReading(model.VehicleNumber);

                                    if (gpsDetails != null)
                                    {
                                        trip.MeterReadingInGps    = Convert.ToInt32(!string.IsNullOrEmpty(gpsDetails.meter_reading));
                                        trip.MeterReadingInStatus = gpsDetails.error;
                                        trip.MeterReadingInGap    = (trip.MeterReadingInGps - trip.MeterReadingIn);
                                    }
                                }

                                //update vehicle meter reading
                                await Task.Run(() => _vehicleService.UpdateMeterReading(model.VehicleId, Convert.ToInt32(model.MeterReadingIn)));

                                //save trip details
                                await Task.Run(() => _tripService.EditTrip(model.TripId, trip));

                                await Task.Run(() => _tripService.ArchiveTripById(model.TripId));
                            }
                        }
                        else
                        {
                            message = "Error in meter reading in";
                        }
                    }
                    else
                    {
                        message = "Driver cannot be null";
                    }
                }
                else
                {
                    message = "Vehicle cannot be null";
                }
                return(Json(message, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                return(Json(e.Message));
            }
        }