public async Task AddVehicleModel(VehicleModelDTO vehicleModelDto)
        {
            if (!await IsValidVehicleMake(vehicleModelDto.VehicleMakeId))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.VEHICLE_MAKE_NOT_EXIST);
            }

            vehicleModelDto.Name = vehicleModelDto.Name.Trim();

            var vehicleModelName = vehicleModelDto.Name.ToLower();

            if (await _vehicleModelRepo.ExistAsync(v => v.Name.ToLower() == vehicleModelName))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.VEHICLE_MODEL_EXIST);
            }

            _vehicleModelRepo.Insert(new VehicleModel
            {
                Name          = vehicleModelDto.Name,
                NumberOfSeats = vehicleModelDto.NumberOfSeats,
                VehicleMakeId = vehicleModelDto.VehicleMakeId
            });

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task <CouponDTO> GetValidCouponByPhone(string couponCode, string phone)
        {
            var coupon = await GetCouponByCodeAsync(couponCode);

            if (coupon == null)
            {
                throw await _serviceHelper.GetExceptionAsync("Coupon does not exist");
            }
            coupon = await GetValidCouponByCodeAsync(couponCode);

            if (coupon == null)
            {
                throw await _serviceHelper.GetExceptionAsync("Coupon is invalid");
            }

            var couponexpiryDate = await GetCouponExpiryDate(couponCode);

            if (DateTime.Now > couponexpiryDate)
            {
                throw await _serviceHelper.GetExceptionAsync("Coupon has Expired");
            }


            var couponuseByGuest = await GetCouponUsedByPhoneAsync(couponCode, phone);

            if (couponuseByGuest != null)
            {
                throw await _serviceHelper.GetExceptionAsync("Coupon already used by Guest");
            }
            return(coupon);
        }
Exemplo n.º 3
0
        public async Task UpdateDiscount(Guid discountid, DiscountDTO discount)
        {
            var existingDiscount = await _discountRepo.GetAsync(discountid);

            if (discount == null)
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.DISCOUNT_NOT_EXIST);
            }



            existingDiscount.MinorDiscount = discount.MinorDiscount;

            existingDiscount.AdultDiscount = discount.AdultDiscount;

            existingDiscount.MemberDiscount           = discount.MemberDiscount;
            existingDiscount.AppDiscountIos           = discount.AppDiscountIos;
            existingDiscount.AppDiscountAndroid       = discount.AppDiscountAndroid;
            existingDiscount.AppDiscountWeb           = discount.AppDiscountWeb;
            existingDiscount.AppReturnDiscountIos     = discount.AppReturnDiscountIos;
            existingDiscount.AppReturnDiscountAndroid = discount.AppReturnDiscountAndroid;
            existingDiscount.AppReturnDiscountWeb     = discount.AppReturnDiscountWeb;
            existingDiscount.ReturnDiscount           = discount.ReturnDiscount;
            existingDiscount.PromoDiscount            = discount.PromoDiscount;
            existingDiscount.Active           = discount.Active;
            existingDiscount.CustomerDiscount = discount.CustomerDiscount;

            existingDiscount.BookingType = discount.BookingType;

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public async Task <FranchiseUserDTO> GetFranchiseUser(int id)
        {
            var franchise = await _repo.GetAsync(id);

            if (franchise == null)
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.FRANCHISE_NOT_EXIST);
            }

            return(new FranchiseUserDTO
            {
                Id = franchise.Id,
                FirstName = franchise.FirstName,
                MiddleName = franchise.MiddleName,
                LastName = franchise.LastName,
                Address = franchise.Address,
                IsFirstTimeLogin = franchise.IsFirstTimeLogin,
                OptionalPhoneNumber = franchise.OptionalPhoneNumber,
                Image = franchise.Image,
                RefreshToken = franchise.RefreshToken,
                Title = franchise.Title,
                DeviceToken = franchise.DeviceToken,
                Referrer = franchise.Referrer,
                ReferralCode = franchise.ReferralCode,
                NextOfKinName = franchise.NextOfKinName,
                NextOfKinPhone = franchise.NextOfKinPhone,
                DateOfBirth = franchise.DateOfBirth,
                AccountConfirmationCode = franchise.AccountConfirmationCode,
                Photo = franchise.Photo,
                OTP = franchise.OTP,
                PhoneNumber = franchise.PhoneNumber,
                Email = franchise.Email
            });
        }
Exemplo n.º 5
0
        public async Task <MtuReportModelDTO> GetReportById(int id)
        {
            var report = await _mtuRepo.GetAsync(id);

            if (report == null)
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.NULL_ENTRY_REJECTED);
            }

            var pics = from pic in _mtuPhotoRepo.GetAll()
                       where pic.MtuReportModelId == id
                       select new MtuPhoto
            {
                FileName = pic.FileName,
                Id       = pic.Id
            };

            return(new MtuReportModelDTO
            {
                Id = report.Id,
                Notes = report.Notes,
                Email = report.Email,
                FullName = report.FullName,
                Date = report.CreationTime,
                VehicleId = report.VehicleId,
                RegistrationNumber = report.RegistrationNumber,
                DriverCode = report.DriverId,
                Status = report.Status,
                VehicleStatus = report.Status.ToString(),
                Picture = report.Picture,
                MtuPhotos = pics.ToListAsync().Result
            });
        }
Exemplo n.º 6
0
        public async Task <ComplaintDTO> GetComplaintById(int id)
        {
            var complaint = await _complaintRepo.GetAsync(id);

            if (complaint == null)
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.NULL_ENTRY_REJECTED);
            }

            return(new ComplaintDTO
            {
                Id = complaint.Id,
                BookingReference = complaint.BookingReference,
                Complaints = complaint.ComplaintType.ToString(),
                Message = complaint.Message,
                FullName = complaint.FullName,
                Email = complaint.Email,
                PriorityLevel = complaint.PriorityLevel,
                Priority = complaint.PriorityLevel.ToString(),
                CreationTime = complaint.CreationTime,
                ComplaintType = complaint.ComplaintType,
                Responded = complaint.Responded,
                RepliedMessage = complaint.RepliedMessage
            });
        }
Exemplo n.º 7
0
        public async Task <OrderDto> GetOrderById(int orderId)
        {
            var request = await _orderRepository.GetAsync(orderId);

            if (request == null)
            {
                throw await _helper.GetExceptionAsync("Order entry does not exist");
            }
            return(_mapper.Map <OrderDto>(request));
        }
Exemplo n.º 8
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.º 9
0
        public async Task <DriverDTO> GetDriverById(int?id)
        {
            var driver =
                await(from Driver in _driverRepo.GetAll()
                      join wallet in _walletSvc.GetAll() on Driver.WalletId equals wallet.Id
                      where Driver.Id == id

                      select new DriverDTO
            {
                DriverDetails                  = Driver.Name + " - " + Driver.Code + " ( " + Driver.DriverStatus + " )",
                Id                             = Driver.Id,
                Code                           = Driver.Code,
                HandoverCode                   = Driver.HandoverCode,
                DriverStatus                   = Driver.DriverStatus,
                DriverType                     = Driver.DriverType,
                Name                           = Driver.Name,
                Phone1                         = Driver.Phone1,
                Phone2                         = Driver.Phone2,
                Designation                    = Driver.Designation,
                AssignedDate                   = Driver.AssignedDate,
                ResidentialAddress             = Driver.ResidentialAddress,
                NextOfKin                      = Driver.NextOfKin,
                DateCreated                    = Driver.CreationTime,
                Picture                        = Driver.Picture,
                Active                         = Driver.Active,
                NextOfKinNumber                = Driver.NextOfKinNumber,
                BankName                       = Driver.BankName,
                BankAccount                    = Driver.BankAccount,
                DeactivationReason             = Driver.DeactivationReason,
                ActivationStatusChangedByEmail = Driver.ActivationStatusChangedByEmail,
                WalletId                       = wallet.Id,
                WalletBalance                  = wallet.Balance,
                WalletNumber                   = wallet.WalletNumber,
                MaintenanceWalletId            = Driver.MaintenanceWalletId,
                NoOfTrips                      = Driver.NoOfTrips,
                VehicleNumber                  = Driver.VehicleRegistrationNumber
            }).FirstOrDefaultAsync();

            if (driver is null)
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.DRIVER_NOT_EXIST);
            }

            return(driver);
        }
Exemplo n.º 10
0
        public async Task <FranchiseDTO> GetFranchiseById(int id)
        {
            var franchise = await _franchise.GetAsync(id);

            if (franchise == null)
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.FRANCHISE_NOT_EXIST);
            }

            return(new FranchiseDTO
            {
                Id = franchise.Id,
                Name = franchise.Name,
                FirstName = franchise.FirstName,
                LastName = franchise.LastName,
                Code = franchise.Code,
                PhoneNumber = franchise.PhoneNumber
            });
        }
Exemplo n.º 11
0
        public async Task <EquipmentDto> GetEquipmentById(int id)
        {
            var request = await _equipment.GetAsync(id);//_uow.Equipment.GetAsync(id);

            if (request == null)
            {
                throw await _helper.GetExceptionAsync("Equipment entry does not exist");
            }
            return(_mapper.Map <Equipment, EquipmentDto>(request));
        }
Exemplo n.º 12
0
        public async Task <CartItemDto> CartItemsByIdAsync(Guid cartId)
        {
            var item = _cartRepository.CartItemsById(cartId);

            if (item == null)
            {
                throw await _helper.GetExceptionAsync("Cart entry does not exist");
            }
            return(_mapper.Map <CartItemDto>(item));
        }
Exemplo n.º 13
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.º 14
0
        public async Task <FareDTO> GetFareById(int fareId)
        {
            var fare = await _repo.GetAsync(fareId);

            if (fare == null)
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.FARE_NOT_EXIST);
            }

            return(new FareDTO
            {
                Id = fare.Id,
                Name = fare.Name,
                Amount = fare.Amount,
                RouteId = fare.RouteId,
                RouteName = fare?.Route?.Name,
                VehicleModelId = fare.VehicleModelId,
                VehicleModelName = fare?.VehicleModel?.Name,
                ChildrenDiscountPercentage = fare.ChildrenDiscountPercentage
            });
        }
Exemplo n.º 15
0
        public async Task <RouteDTO> GetRouteById(int routeId)
        {
            var route = await _repo.GetAsync(routeId);

            if (route is null)
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.ROUTE_NOT_EXIST);
            }

            return(new RouteDTO
            {
                Id = route.Id,
                Name = route.Name,
                RouteType = route.Type,
                DriverFee = route.DriverFee,
                DispatchFee = route.DispatchFee,
                LoaderFee = route.LoaderFee,
                AvailableOnline = route.AvailableOnline,
                AvailableAtTerminal = route.AvailableAtTerminal,
                ParentRouteId = route.ParentRouteId,
                DestinationTerminalId = route.DestinationTerminalId,
                DepartureTerminalId = route.DepartureTerminalId,
                ParentRouteName = route.ParentRoute
            });
        }
Exemplo n.º 16
0
        public async Task AddTrip(TripDTO tripDto)
        {
            if (!await IsValidRoute(tripDto.RouteId))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.ROUTE_NOT_EXIST);
            }

            if (!await IsValidVehicleModel(tripDto.VehicleModelId.GetValueOrDefault()))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.VEHICLE_MODEL_NOT_EXIST);
            }

            _tripRepo.Insert(new Trip
            {
                DepartureTime            = tripDto.DepartureTime,
                TripCode                 = tripDto.Code,
                RouteId                  = tripDto.RouteId,
                ParentRouteId            = tripDto.ParentRouteId,
                ParentRouteDepartureTime = tripDto.ParentDepartureTime,
                ParentTripId             = tripDto.ParentTripId,
                VehicleModelId           = tripDto.VehicleModelId,
                AvailableOnline          = tripDto.AvailableOnline
            });

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 17
0
        public async Task AddTerminal(TerminalDTO terminalDto)
        {
            if (!await IsValidState(terminalDto.StateId))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.STATE_NOT_EXIST);
            }

            terminalDto.Name = terminalDto.Name.Trim();


            if (await _terminalRepo.ExistAsync(v => v.Name.Equals(terminalDto.Name)))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.TERMINAL_EXIST);
            }

            if (terminalDto.StartDate is null)
            {
                terminalDto.StartDate = Clock.Now;
            }

            _terminalRepo.Insert(new Terminal
            {
                Id                = terminalDto.Id,
                Name              = terminalDto.Name,
                Code              = terminalDto.Code,
                Image             = terminalDto.Image,
                Address           = terminalDto.Address,
                ContactPerson     = terminalDto.ContactPerson,
                ContactPersonNo   = terminalDto.ContactPersonNo,
                Latitude          = terminalDto.Latitude,
                Longitude         = terminalDto.Longitude,
                StateId           = terminalDto.StateId,
                TerminalType      = terminalDto.TerminalType,
                TerminalStartDate = terminalDto.StartDate.GetValueOrDefault()
            });

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 18
0
        public async Task AddState(StateDTO stateDto)
        {
            if (!await IsValidRegion(stateDto.RegionId))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.REGION_NOT_EXIST);
            }

            stateDto.Name = stateDto.Name.Trim();

            if (await _stateRepo.ExistAsync(v => v.Name == stateDto.Name))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.STATE_EXIST);
            }

            _stateRepo.Insert(new State
            {
                Id       = stateDto.Id,
                Name     = stateDto.Name,
                RegionId = stateDto.RegionId
            });

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 19
0
        public async Task UpdateFareCalendar(int Id, FareCalendarDTO fareCalendarDto)
        {
            var calendar = await _repo.GetAsync(Id);

            if (calendar == null)
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.FareCalendar_NOT_EXIST);
            }



            calendar.Name               = fareCalendarDto.Name.Trim();
            calendar.StartDate          = fareCalendarDto.StartDate;
            calendar.EndDate            = fareCalendarDto.EndDate;
            calendar.RouteId            = fareCalendarDto.RouteId;
            calendar.TerminalId         = fareCalendarDto.TerminalId;
            calendar.FareParameterType  = fareCalendarDto.FareParameterType;
            calendar.FareAdjustmentType = fareCalendarDto.FareAdjustmentType;
            calendar.VehicleModelId     = fareCalendarDto.VehicleModelId;
            calendar.FareType           = fareCalendarDto.FareType;
            calendar.FareValue          = fareCalendarDto.FareValue;

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 20
0
        public async Task <List <SubRouteDTO> > GetRouteById(int routeId)
        {
            var subroutes =
                from subroute in _repo.GetAll()
                join route in _routeRepo.GetAll() on subroute.RouteId equals route.Id

                where route.Id == routeId

                select new SubRouteDTO
            {
                RouteId   = route.Id,
                RouteName = route.Name,
                Id        = subroute.Id,
                NameId    = subroute.NameId,
                Name      = subroute.Name
            };

            if (subroutes is null)
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.ROUTE_NOT_EXIST);
            }

            return(await subroutes.AsNoTracking().ToListAsync());
        }
Exemplo n.º 21
0
        //private async Task<bool> IsValidRegion(int passportTypeId)
        //{
        //    return regionId > 0 &&
        //         await _passportTypeRepo.ExistAsync(m => m.Id == regionId);
        //}

        public async Task AddPassportType(PassportTypeDTO passportType)
        {
            //if (!await IsValidRegion(passportType.Id)) {
            //    throw await _serviceHelper.GetExceptionAsync(ErrorConstants.REGION_NOT_EXIST);
            //}

            passportType.Name = passportType.Name.Trim();

            if (await _passportTypeRepo.ExistAsync(v => v.Name == passportType.Name))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.STATE_EXIST);
            }

            _passportTypeRepo.Insert(new PassportType
            {
                Id          = passportType.Id,
                Name        = passportType.Name,
                Description = passportType.Description,
                RouteId     = passportType.RouteId,
                AddOnFare   = passportType.AddOnFare
            });

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 22
0
        public async Task AddVehicle(VehicleDTO vehicleDto)
        {
            if (!await IsValidVehicleModel(vehicleDto.VehicleModelId))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.VEHICLE_MODEL_NOT_EXIST);
            }

            if (vehicleDto.DriverId != null && !await IsValidDriver(vehicleDto.DriverId.Value))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.DRIVER_NOT_EXIST);
            }

            // new vehicles are operational
            vehicleDto.IsOperational = true;

            vehicleDto.RegistrationNumber = vehicleDto.RegistrationNumber.Trim();

            var vehicleRegNumber = vehicleDto.RegistrationNumber.ToLower();

            if (await _vehicleRepo.ExistAsync(v => v.RegistrationNumber.ToLower() == vehicleRegNumber))
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.VEHICLE_EXIST);
            }

            var vehicle = new Vehicle
            {
                RegistrationNumber = vehicleDto.RegistrationNumber,
                ChasisNumber       = vehicleDto.ChasisNumber,
                EngineNumber       = vehicleDto.EngineNumber,
                IMEINumber         = vehicleDto.IMEINumber,
                Type           = vehicleDto.Type,
                Status         = vehicleDto.VehicleStatus,
                VehicleModelId = vehicleDto.VehicleModelId,
                LocationId     = vehicleDto.LocationId,
                IsOperational  = vehicleDto.IsOperational,
                DriverId       = vehicleDto.DriverId,
                FranchizeId    = vehicleDto.FranchizeId
            };

            _vehicleRepo.Insert(vehicle);

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 23
0
        public async Task <UserDTO> ActivateAccount(string usernameOrEmail, string activationCode)
        {
            if (string.IsNullOrEmpty(usernameOrEmail) || string.IsNullOrEmpty(activationCode))
            {
                throw await _svcHelper.GetExceptionAsync(ErrorConstants.USER_ACCOUNT_NOT_EXIST);
            }

            var user = await FindByNameAsync(usernameOrEmail) ?? await FindByEmailAsync(usernameOrEmail);

            await ValidateUser(user);

            if (user.IsConfirmed())
            {
                throw new LMEGenericException("Your account was activated earlier.");
            }

            if (activationCode == user.AccountConfirmationCode)
            {
                user.EmailConfirmed       = true;
                user.PhoneNumberConfirmed = true;

                await UpdateAsync(user);
            }
            else if (activationCode != user.AccountConfirmationCode)
            {
                throw  new LMEGenericException("Invalid OTP");
                //await _svcHelper.GetExceptionAsync(ErrorConstants.USER_ACCOUNT_INVALID_OTP);
            }

            return(user == null ? null : new UserDTO
            {
                PhoneNumber = user.PhoneNumber,
                Email = user.Email,
                FirstName = user.FirstName,
                LastName = user.LastName,
                UserId = user.Id,
                Gender = user.Gender,
                IsActive = user.IsConfirmed(),
                AccountIsDeleted = user.IsDeleted,
            });
        }
Exemplo n.º 24
0
        public async Task <UserDTO> CreateAccount(CustomerDTO customerDTO)
        {
            if (customerDTO is null)
            {
                throw new ArgumentNullException(nameof(customerDTO));
            }

            var customer = await _userManagerSvc.FindFirstAsync(c => c.Email == customerDTO.Email ||
                                                                c.PhoneNumber.Trim() == customerDTO.Phone);

            customer = new User
            {
                UserName                = customerDTO.Phone,
                Title                   = customerDTO.Title,
                FirstName               = customerDTO.FirstName,
                MiddleName              = customerDTO.MiddleName,
                LastName                = customerDTO.LastName,
                DateOfBirth             = customerDTO.DateOfBirth,
                Email                   = customerDTO.Email,
                Address                 = customerDTO.Address,
                PhoneNumber             = customerDTO.Phone,
                OptionalPhoneNumber     = customerDTO.OptionalPhoneNumber,
                NextOfKinName           = customerDTO.NextOfKinName,
                NextOfKinPhone          = customerDTO.NextOfKinPhone,
                ReferralCode            = CommonHelper.GenereateRandonAlphaNumeric(),
                Referrer                = customerDTO.ReferralCode,
                UserType                = UserType.Customer,
                AccountConfirmationCode = _guidGenerator.Create().ToString().Substring(0, 8)
            };

            var customerAcctResult = !string.IsNullOrWhiteSpace(customerDTO.Password)
                             ? await _userManagerSvc.CreateAsync(customer, customerDTO.Password)
                             : await _userManagerSvc.CreateAsync(customer);

            if (customerAcctResult.Succeeded)
            {
                // await _userManagerSvc.AddToRoleAsync(customer, CoreConstants.Roles.Customer);

                //Password customer created from front-end, backend create non-password
                if (!string.IsNullOrWhiteSpace(customer.PasswordHash))
                {
                    await SendActivationMessage(customer);
                }
                //    if (!String.IsNullOrEmpty(customer.ReferralCode)) {
                //        _smsSvc.SendSMSNow($"Your referrer code is {customer.ReferralCode}", recipient: customer.PhoneNumber);
                //    }


                return(new UserDTO
                {
                    PhoneNumber = customer.PhoneNumber,
                    Email = customer.Email,
                    FirstName = customer.FirstName,
                    LastName = customer.LastName,
                    UserId = customer.Id,
                    IsActive = customer.EmailConfirmed,
                    AccountIsDeleted = customer.IsDeleted,
                    ReferralCode = customer.ReferralCode
                });
            }
            else
            {
                throw await _svcHelper.GetExceptionAsync(customerAcctResult.Errors.FirstOrDefault()?.Description);
            }
        }
        public async Task CreatePhysicalBus(TerminalBookingDTO physicalbus)
        {
            var trip = await _tripSvc.GetTripById(physicalbus.TripId);

            var vehicle = await _vehicleSvc.GetVehicleById(physicalbus.VehicleId);

            DateTime departuredate = Clock.Now.Date;

            var asignedVehicleDto = await _vehicleSvc.GetVehiclesByRegNum(vehicle.RegistrationNumber);

            if (asignedVehicleDto == null)
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.VEHICLE_NOT_EXIST);
            }
            var assignedVehicle = await _vehicleSvc.GetVehicleById(physicalbus.VehicleId);

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

            var employee = await _employeeSvc.GetEmployeesByemailAsync(email.Email);

            if (employee != null && employee.TerminalId != null && assignedVehicle.VehicleStatus != VehicleStatus.InWorkshop)
            {
                assignedVehicle.LocationId = employee.TerminalId;
            }
            //assignedVehicle.Location = null;
            if (assignedVehicle != null && assignedVehicle.VehicleStatus != VehicleStatus.InWorkshop)
            {
                assignedVehicle.VehicleStatus = VehicleStatus.TerminalUse;
            }
            if (assignedVehicle != null && assignedVehicle.VehicleStatus == VehicleStatus.InWorkshop)
            {
                assignedVehicle.VehicleStatus = VehicleStatus.InWorkshopAndAssigned;
            }
            //Get assigned Captain and Update
            var assignedCaptainDto = await _driverSvc.GetActiveDriverByCodeAsync(physicalbus.DriverCode);

            if (assignedCaptainDto == null)
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.DRIVER_NOT_EXIST);
            }

            var assignedDrv = await _driverSvc.GetAsync(assignedCaptainDto.Id);

            var phyBus = new VehicleTripRegistration
            {
                PhysicalBusRegistrationNumber = vehicle.RegistrationNumber,
                DepartureDate  = departuredate,
                TripId         = physicalbus.TripId,
                DriverCode     = physicalbus.DriverCode,
                VehicleModelId = trip.VehicleModelId,
                IsVirtualBus   = false,
                JourneyType    = JourneyType.Loaded
            };


            if (assignedDrv.DriverType == DriverType.Virtual)
            {
                if (string.IsNullOrEmpty(physicalbus.OriginalDriverCode))
                {
                    throw new LMEGenericException("Could not create vehicle because you did not choose the original captain that will take the trip");
                }

                phyBus.OriginalDriverCode = physicalbus.OriginalDriverCode;
            }
            else
            {
                phyBus.OriginalDriverCode = "";
            }

            _repo.Insert(phyBus);

            await _unitOfWork.SaveChangesAsync();
        }
Exemplo n.º 26
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;
            }
        }
Exemplo n.º 27
0
        public async Task <IServiceReponse <bool> > Register(UserDto registration, UserType userType = UserType.Employee)
        {
            return(await HandleApiOperationAsync(async() =>
            {
                if (await _userManager.UserExistsAsync(registration.Email))
                {
                    throw await _helper.GetExceptionAsync(ErrorConstants.UserAccountExists);
                }

                if (!await _userManager.RolesExistAsync(registration.Roles ?? new List <string>()))
                {
                    throw await _helper.GetExceptionAsync(ErrorConstants.RoleNotExist);
                }

                var user = registration.MapTo <User>();

                user.UserType = userType;
                user.IsActive = true;

                var password = _passwordGenerator.Generate();

                if (!await _userManager.CreateUserAsync(user, password, registration.Roles ?? new List <string>()))
                {
                    throw await _helper.GetExceptionAsync(ErrorConstants.UserAccountRegistrationFailed);
                }

                await _messagingFactory.GetEmailManager().SendAsync(
                    "Business Mobility",
                    user.Email,
                    "Welcome to Business!",
                    $"<div> username: {user.Email } </div> <div> password: {password} </div>",
                    true
                    );

                return new ServiceResponse <bool>(true);
            }));
        }
Exemplo n.º 28
0
        public async Task UpdateOpenManifest(Guid vehicleRegistrationId)
        {
            var manifest = await GetManifestPassengersByVehicleTripIdAsync(vehicleRegistrationId);

            var existingManifestManagement = await _repository.GetAsync(manifest.Id);

            if (existingManifestManagement == null)
            {
                throw await _serviceHelper.GetExceptionAsync(ErrorConstants.MANIFEST_MANAGEMENT_NOT_EXIST);
            }


            existingManifestManagement.IsPrinted = false;


            await _unitOfWork.SaveChangesAsync();
        }