Exemplo n.º 1
0
        public async Task AddDriver(DriverDTO driver)
        {
            driver.Code = driver.Code.Trim();

            if (await _driverRepo.ExistAsync(v => v.Code == driver.Code))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.DRIVER_EXIST);
            }

            var walletNumber = await _walletSvc.GenerateNextValidWalletNumber();

            _walletNumberRepo.Insert(walletNumber);

            var wallet = new Wallet
            {
                WalletNumber  = walletNumber.WalletPan,
                CreatorUserId = _serviceHelper.GetCurrentUserId(),
                Balance       = 0.00M,
                UserType      = UserType.Captain.ToString()
            };

            _walletSvc.Add(wallet);

            _driverRepo.Insert(new Driver
            {
                Code               = driver.Code,
                CreatorUserId      = _serviceHelper.GetCurrentUserId(),
                DriverStatus       = driver.DriverStatus,
                DriverType         = driver.DriverType,
                HandoverCode       = driver.HandoverCode,
                Name               = driver.Name,
                Phone1             = driver.Phone1,
                Phone2             = driver.Phone2,
                Designation        = driver.Designation,
                AssignedDate       = driver.AssignedDate,
                ResidentialAddress = driver.ResidentialAddress,
                NextOfKin          = driver.NextOfKin,
                Picture            = driver.Picture,
                Active             = true,
                NextOfKinNumber    = driver.NextOfKinNumber,
                BankName           = driver.BankName,
                BankAccount        = driver.BankAccount,
                DeactivationReason = driver.DeactivationReason,
                WalletId           = wallet.Id,
                NoOfTrips          = 0,
                DateOfEmployment   = driver.DateOfEmployment
            });

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task AddFare(FareDTO fareDto)
        {
            if (await IsDefinedFareAsync(fareDto.RouteId, fareDto.VehicleModelId))
            {
                throw new LMEGenericException($"Fare already exist!");
            }

            if (!await IsValidRoute(fareDto.RouteId))
            {
                throw new LMEGenericException($"Route does not exist!");
            }

            if (!await IsValidVehicleModel(fareDto.VehicleModelId))
            {
                throw new LMEGenericException($"Route does not exist!");
            }

            _repo.Insert(new Fare
            {
                Amount                     = fareDto.Amount,
                CreatorUserId              = _serviceHelper.GetCurrentUserId(),
                RouteId                    = fareDto.RouteId,
                VehicleModelId             = fareDto.VehicleModelId,
                ChildrenDiscountPercentage = fareDto.ChildrenDiscountPercentage
            });

            await _unitOfWork.SaveChangesAsync();
        }
        public AccountSummary CreateOrUpdateEntry(AccountSummary accountSummary)
        {
            if (accountSummary is null)
            {
                throw new Exception("Null entry rejected");
            }

            var existing = _repo.FirstOrDefault(a => a.AccountName == accountSummary.AccountName);


            if (existing != null)
            {
                existing.Balance += accountSummary.Balance;
            }

            else
            {
                existing = new AccountSummary()
                {
                    Id            = SequentialGuidGenerator.Instance.Create(),
                    IsDeleted     = false,
                    CreatorUserId = _serviceHelper.GetCurrentUserId(),
                    AccountName   = accountSummary.AccountName,
                    Balance       = accountSummary.Balance,
                };

                _repo.Insert(existing);
            }
            return(existing);
        }
        public Task <IEnumerable <SeatManagementDTO> > GetSeatHistoryAsync()
        {
            var seat =
                from seatMgt in GetAll()
                join route in _routeRepo.GetAll() on seatMgt.RouteId equals route.Id
                where seatMgt.CreatorUserId == _serviceHelper.GetCurrentUserId()
                orderby seatMgt.CreationTime descending

                select new SeatManagementDTO
            {
                refCode                   = seatMgt.BookingReferenceCode,
                Id                        = seatMgt.Id,
                SeatNumber                = seatMgt.SeatNumber,
                RemainingSeat             = seatMgt.RemainingSeat,
                CreatedBy                 = seatMgt.CreatedBy,
                BookingReferenceCode      = seatMgt.BookingReferenceCode,
                FromTransload             = seatMgt.FromTransload,
                Amount                    = seatMgt.Amount,
                Discount                  = seatMgt.Discount,
                PassengerType             = seatMgt.PassengerType,
                PaymentMethod             = seatMgt.PaymentMethod,
                BookingType               = seatMgt.BookingType,
                RouteId                   = seatMgt.RouteId,
                VehicleTripRegistrationId = seatMgt.VehicleTripRegistrationId,
                FullName                  = seatMgt.FullName,
                Gender                    = seatMgt.Gender,
                PhoneNumber               = seatMgt.PhoneNumber,
                NextOfKinName             = seatMgt.NextOfKinName,
                NextOfKinPhoneNumber      = seatMgt.NextOfKinPhoneNumber,
                DateCreated               = seatMgt.CreationTime,
                IsMainBooker              = seatMgt.IsMainBooker,
                HasReturn                 = seatMgt.HasReturn,
                MainBookerReferenceCode   = seatMgt.MainBookerReferenceCode,
                IsReturn                  = seatMgt.IsReturn,
                NoOfTicket                = seatMgt.NoOfTicket,
                RouteName                 = route.Name,
                VehicleTripRegistration   = seatMgt.VehicleTripRegistrationId.ToString(),
                DepartureDate             = seatMgt.VehicleTripRegistration.DepartureDate,
                PickupPointName           = seatMgt.PickupPoint.Name,
                VehicleName               = seatMgt.VehicleTripRegistration.PhysicalBusRegistrationNumber,
                BookingStatus             = seatMgt.BookingStatus,
                TravelStatus              = seatMgt.TravelStatus,
                DepartureTime             = seatMgt.VehicleTripRegistration.Trip.DepartureTime,
                DepartureTerminalName     = seatMgt.VehicleTripRegistration.Trip.Route.DepartureTerminal.Name,
                DestinationTerminalName   = seatMgt.VehicleTripRegistration.Trip.Route.DestinationTerminal.Name,
                DestinationTerminalId     = seatMgt.Route.DestinationTerminalId,
                DepartureTerminald        = seatMgt.Route.DepartureTerminalId,
                Rated                     = seatMgt.Rated,
                IsRescheduled             = seatMgt.IsRescheduled,
                RescheduleStatus          = seatMgt.RescheduleStatus,
                HasCoupon                 = seatMgt.HasCoupon,
                CouponCode                = seatMgt.CouponCode
            };

            return(Task.FromResult(seat.AsNoTracking().AsEnumerable()));
        }
Exemplo n.º 5
0
        public async Task AddSubRoute(SubRouteDTO subrouteDto)
        {
            var subroute = await _routeRepo.GetAsync(subrouteDto.NameId.GetValueOrDefault());

            _repo.Insert(new SubRoute
            {
                RouteId       = subrouteDto.RouteId,
                CreatorUserId = _serviceHelper.GetCurrentUserId(),
                NameId        = subrouteDto.NameId.GetValueOrDefault(),
                Name          = subroute.Name
            });

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 6
0
        public async Task AddVehicleMake(VehicleMakeDTO vehicleMakeDto)
        {
            vehicleMakeDto.Name = vehicleMakeDto.Name.Trim();

            if (await _vehicleMakeRepo.ExistAsync(v => v.Name == vehicleMakeDto.Name))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.VEHICLE_MAKE_EXIST);
            }

            _vehicleMakeRepo.Insert(new VehicleMake
            {
                Name          = vehicleMakeDto.Name,
                CreatorUserId = _serviceHelper.GetCurrentUserId()
            });

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 7
0
        public async Task AddRegion(RegionDTO regionDto)
        {
            regionDto.Name = regionDto.Name.Trim();

            var regionName = regionDto.Name.ToLower();

            if (await _regionRepo.ExistAsync(v => v.Name.ToLower() == regionName))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.REGION_EXIST);
            }

            _regionRepo.Insert(new Region
            {
                Name          = regionDto.Name,
                CreatorUserId = _serviceHelper.GetCurrentUserId()
            });

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 8
0
        public async Task CreateRequest(HireRequestDTO hireRequest)
        {
            if (hireRequest is null)
            {
                throw new LMEGenericException($"Request is invalid.");
            }

            if (hireRequest.RequestDate < Clock.Now)
            {
                throw new LMEGenericException($"Request date cannot be in the past.");
            }

            if (hireRequest.DepartureDate < Clock.Now)
            {
                throw new LMEGenericException($"Departure date cannot be in the past.");
            }

            _repo.Insert(new HireRequest
            {
                Address              = hireRequest.Address,
                CreatorUserId        = _serviceHelper.GetCurrentUserId(),
                Departure            = hireRequest.Departure,
                DepartureDate        = hireRequest.DepartureDate,
                Destination          = hireRequest.Destination,
                Email                = hireRequest.Email,
                FirstName            = hireRequest.FirstName,
                Gender               = hireRequest.Gender,
                LastName             = hireRequest.LastName,
                MiddleName           = hireRequest.MiddleName,
                NextOfKinName        = hireRequest.NextOfKinName,
                NextOfKinPhoneNumber = hireRequest.NextOfKinPhoneNumber,
                NumberOfBuses        = hireRequest.NumberOfBuses,
                PhoneNumber          = hireRequest.PhoneNumber,
                RequestDate          = hireRequest.RequestDate
            });

            await _unitOfWork.SaveChangesAsync();

            await SendRequestEmail(hireRequest);
        }
        private void AddEntry(Guid vehicleTripRegistrationId, string refcode, decimal amount, TransactionType transType = TransactionType.Credit)
        {
            var transEntry = new AccountTransaction
            {
                Id                   = SequentialGuidGenerator.Instance.Create(),
                AccountType          = AccountType.BookingAccount,
                LastModificationTime = Clock.Now,
                CreatorUserId        = _serviceHelper.GetCurrentUserId(),
                TransactionDate      = Clock.Now,
                TransactionSourceId  = vehicleTripRegistrationId,
                Narration            = refcode
            };

            var summary = new AccountSummary
            {
                Id          = SequentialGuidGenerator.Instance.Create(),
                AccountName = _serviceHelper.GetCurrentUserEmail()
            };

            switch (transType)
            {
            case TransactionType.Credit:

                transEntry.TransactionType = transType;
                transEntry.Amount          = Convert.ToDouble(amount);
                summary.Balance            = Convert.ToDouble(amount);

                break;

            case TransactionType.Debit:

                transEntry.TransactionType = transType;
                transEntry.Amount          = -Convert.ToDouble(amount);
                summary.Balance            = -Convert.ToDouble(amount);
                break;
            }

            _repo.Insert(transEntry);
            _AccountSummarySvc.CreateOrUpdateEntry(summary);
        }
Exemplo n.º 10
0
        public async Task <bool> AllocateBuses(VehicleAllocationDTO queryDto)
        {
            if (!string.IsNullOrEmpty(queryDto.Type.ToString()) && queryDto.Type.ToString() != "0")
            {
                await SendAllocateMessage(queryDto);
            }
            else
            {
                string   AllRegs       = queryDto.RegistrationNumber;
                string[] AllRegsvalues = AllRegs.Split(',');
                dynamic  test          = AllRegsvalues;
                foreach (var item in AllRegsvalues)
                {
                    if (item == "")
                    {
                        continue;
                    }
                    else if (item != null)
                    {
                        int id      = Convert.ToInt32(item.ToString());
                        var vehicle = await _vehicleRepo.GetAsync(id);

                        vehicle.VehicleModel = await _vehicleModelRepo.GetAsync(vehicle.VehicleModelId);

                        var email = await _userSvc.FindByNameAsync(_serviceHelper.GetCurrentUserEmail());

                        queryDto.Email     = email.Email;
                        vehicle.LocationId = queryDto.LocationId;
                        vehicle.Status     = VehicleStatus.Idle; //new

                        var check = _vehicleAlloRepo.GetAll().Where(s => s.VehicleId == vehicle.Id && s.TransactionDate.Date == DateTime.UtcNow.Date);

                        if (check.Count() != 0)
                        {
                            check.FirstOrDefault().TransactionDate     = DateTime.Now;
                            check.FirstOrDefault().DestinationTerminal = vehicle.LocationId;

                            await _unitOfWork.SaveChangesAsync();
                        }

                        else if (check.Count() == 0)
                        {
                            _vehicleAlloRepo.Insert(new VehicleAllocationDetailModel
                            {
                                VehicleId           = vehicle.Id,
                                DriverId            = vehicle.DriverId,
                                VehicleName         = vehicle.VehicleModel.Name,
                                DestinationTerminal = vehicle.LocationId,
                                UserEmail           = queryDto.Email,
                                TransactionDate     = DateTime.Now,
                                CreatorUserId       = _serviceHelper.GetCurrentUserId(),
                            });
                        }

                        await _unitOfWork.SaveChangesAsync();
                    }
                    ;
                }
            }
            return(true);
        }
Exemplo n.º 11
0
        public async Task AddEmployee(EmployeeDTO employee)
        {
            if (employee == null)
            {
                throw await _serviceHelper.GetExceptionAsync("invalid parameter");
            }

            if (employee.TerminalId != null && !await IsValidTerminal(employee.TerminalId))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.TERMINAL_NOT_EXIST);
            }

            if (employee.DepartmentId != null && !await IsValidDepartment(employee.DepartmentId))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.DEPARTMENT_NOT_EXIST);
            }

            employee.EmployeeCode = employee.EmployeeCode.Trim();

            if (await _repo.ExistAsync(v => v.EmployeeCode == employee.EmployeeCode))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.EMPLOYEE_EXIST);
            }

            try {
                _unitOfWork.BeginTransaction();

                var user = new User
                {
                    FirstName            = employee.FirstName,
                    LastName             = employee.LastName,
                    MiddleName           = employee.MiddleName,
                    Gender               = employee.Gender,
                    Email                = employee.Email,
                    PhoneNumber          = employee.PhoneNumber,
                    Address              = employee.Address,
                    NextOfKinName        = employee.NextOfKin,
                    NextOfKinPhone       = employee.NextOfKinPhone,
                    EmailConfirmed       = true,
                    PhoneNumberConfirmed = true,
                    UserName             = employee.Email,
                    ReferralCode         = CommonHelper.GenereateRandonAlphaNumeric()
                };

                var creationStatus = await _userSvc.CreateAsync(user, "123456");

                if (creationStatus.Succeeded)
                {
                    var dbRole = await _roleSvc.FindByIdAsync(employee.RoleId);

                    if (dbRole != null)
                    {
                        await _userSvc.AddToRoleAsync(user, dbRole.Name);
                    }

                    _repo.Insert(new Employee
                    {
                        UserId           = user.Id,
                        EmployeeCode     = employee.EmployeeCode,
                        DateOfEmployment = employee.DateOfEmployment,
                        DepartmentId     = employee.DepartmentId,
                        TerminalId       = employee.TerminalId,
                        CreatorUserId    = _serviceHelper.GetCurrentUserId()
                    });


                    await SendAccountEmail(user);
                }
                else
                {
                    _unitOfWork.Rollback();

                    throw await _serviceHelper
                          .GetExceptionAsync(creationStatus.Errors.FirstOrDefault()?.Description);
                }
                _unitOfWork.Commit();
            }
            catch (Exception) {
                _unitOfWork.Rollback();
                throw;
            }
        }