public List <PSPCustomModel> GetPSPs(string email, string apiKey)
        {
            using (PSPService service = new PSPService())
            {
                service.CurrentUser = service.GetUser(email);

                return(service.List1(new PagingModel()
                {
                    Take = int.MaxValue, Skip = 0, Query = string.Empty
                }, new CustomSearchModel()
                {
                    Status = Status.Active
                }));
            }
        }
Beispiel #2
0
        /// <summary>
        /// There's a common use for Branch, DirectorateProject and DepartmentSubProject  etc
        /// This function will help generically retrieve a unique list of the above 3 from a specified table
        /// CAUTION!! Only use this if the table you're trying to query has the above 3 "string" columns and are spelled exactly as above!
        /// If the table doesn't have, then using this function will break your request, if not spelled the same, kindly make it spelled as
        /// above to enjoy me!
        /// LOOK at /Views/PaymentRequisition/_List and then /Views/Shared/_PRCustomSearch for usage
        /// </summary>
        /// <param name="listType"></param>
        public CustomSearchModel(string listType)
        {
            SetDefaults();

            switch (listType)
            {
            case "Users":



                break;


            case "PSPs":
            case "LinkProducts":

                using (ClientService cservice = new ClientService())
                    using (ProductService pservice = new ProductService())
                    {
                        ClientOptions  = cservice.List(true);
                        ProductOptions = pservice.List(true);
                    }

                break;


            case "Regions":

                using (PSPService pservice = new PSPService())
                {
                    PSPOptions = pservice.List(true);
                }

                break;


            case "Clients":

                using (PSPService pservice = new PSPService())
                    using (ClientService cservice = new ClientService())
                    {
                        PSPOptions    = pservice.List(true);
                        ClientOptions = cservice.List(true);
                    }

                break;


            case "SetClient":
            case "ClientKPI":
            case "ReconcileLoads":
            case "MovementReport":
            case "ReconcileInvoice":
            case "ManageTransporters":

                using (ClientService cservice = new ClientService())
                {
                    ClientOptions = cservice.List(true);
                }

                break;


            case "Disputes":
            case "Exceptions":
            case "DeliveryNotes":

                using (SiteService sservice = new SiteService())
                    using (ClientService cservice = new ClientService())
                        using (DisputeReasonService drervice = new DisputeReasonService())
                        {
                            SiteOptions          = sservice.List(true);
                            ClientOptions        = cservice.List(true);
                            DisputeReasonOptions = drervice.List();
                        }

                break;


            case "ChepAudit":
            case "ClientAudit":

                using (SiteService sservice = new SiteService())
                {
                    SiteOptions = sservice.List(true);
                }

                break;


            case "DashBoard":

                using (SiteService sservice = new SiteService())
                    using (RegionService rservice = new RegionService())
                        using (ClientService cservice = new ClientService())
                            using (ProductService pservice = new ProductService())
                            {
                                SiteOptions    = sservice.List(true);
                                RegionOptions  = rservice.List(true);
                                ClientOptions  = cservice.List(true);
                                ProductOptions = pservice.List(true);
                            }

                break;


            case "AuthorisationCodes":

                using (SiteService sservice = new SiteService())
                    using (ClientService cservice = new ClientService())
                        using (TransporterService tservice = new TransporterService())
                        {
                            SiteOptions        = sservice.List(true);
                            ClientOptions      = cservice.List(true);
                            TransporterOptions = tservice.List(true);
                        }

                break;


            case "Billing":

                using (PSPService pservice = new PSPService())
                    using (PSPProductService p1service = new PSPProductService())
                    {
                        PSPOptions        = pservice.List(true);
                        PSPProductOptions = p1service.List(true);
                    }

                break;


            case "ManageSites":

                using (SiteService sservice = new SiteService())
                    using (ClientService cservice = new ClientService())
                        using (RegionService rservice = new RegionService())
                        {
                            SiteOptions   = sservice.List(true);
                            ClientOptions = cservice.List(true);
                            RegionOptions = rservice.List(true);
                        }

                break;


            case "ClientData":

                using (ClientService cservice = new ClientService())
                    using (VehicleService vservice = new VehicleService())
                        //using ( ClientSiteService csservice = new ClientSiteService() )
                        using (TransporterService tservice = new TransporterService())
                            using (OutstandingReasonService urservice = new OutstandingReasonService())
                            {
                                ClientOptions  = cservice.List(true);
                                VehicleOptions = vservice.List(true);
                                //ClientSiteOptions = csservice.List( true );
                                TransporterOptions       = tservice.List(true);
                                OutstandingReasonOptions = urservice.List(true);
                            }

                break;

            case "PODOutstanding":
            case "PoolingAgentData":
            case "OutstandingPallets":
            case "TopOustandingCustomers":
            case "TransporterLiableReport":

                using (ClientService cservice = new ClientService())
                    using (OutstandingReasonService urservice = new OutstandingReasonService())
                    {
                        ClientOptions            = cservice.List(true);
                        OutstandingReasonOptions = urservice.List(true);
                    }

                break;

            case "SiteAudits":

                using (SiteService sservice = new SiteService())
                    using (ClientService cservice = new ClientService())
                    {
                        SiteOptions   = sservice.List(true);
                        ClientOptions = cservice.List(true);
                    }

                break;

            case "PODPerUser":
            case "PODUploadLog":

                using (UserService uservice = new UserService())
                {
                    User1Options = uservice.List(true, RoleType.All);
                }

                break;

            case "AuthorizationCodeAudit":

                using (UserService uservice = new UserService())
                    using (TransporterService tservice = new TransporterService())
                    {
                        TransporterOptions = tservice.List(true);
                        User1Options       = uservice.List(true, RoleType.All);
                    }

                break;

            case "AuditLogPerUser":

                using (UserService uservice = new UserService())
                    using (ClientService cservice = new ClientService())
                        using (VehicleService vservice = new VehicleService())
                            using (PODCommentService pcservice = new PODCommentService())
                                using (TransporterService tservice = new TransporterService())
                                {
                                    ClientOptions      = cservice.List(true);
                                    VehicleOptions     = vservice.List(true);
                                    PODCommentOptions  = pcservice.List(true);
                                    TransporterOptions = tservice.List(true);
                                    User1Options       = uservice.List(true, RoleType.All);
                                }

                break;
            }

            using (ClientService cservice = new ClientService())
            {
                if (cservice.SelectedClient != null && ClientId == 0)
                {
                    ClientId = cservice.SelectedClient.Id;
                }
            }
        }
Beispiel #3
0
        public ActionResult Register(RegisterViewModel model)
        {
            using (PSPService pservice = new PSPService())
                using (UserService uservice = new UserService())
                    using (RoleService rservice = new RoleService())
                        using (ClientService cservice = new ClientService())
                            using (AddressService aservice = new AddressService())
                                using (TransactionScope scope = new TransactionScope())
                                    using (DocumentService dservice = new DocumentService())
                                        using (EstimatedLoadService eservice = new EstimatedLoadService())
                                        {
                                            PSP    psp;
                                            User   user;
                                            Client client;

                                            int    objectId;
                                            string objectType;

                                            model.PSPOptions = pservice.List();

                                            if (!ModelState.IsValid)
                                            {
                                                Notify("The supplied information is not complete. Please try again.", NotificationType.Error);

                                                return(View(model));
                                            }

                                            bool isClient = (model.ServiceType == ServiceType.RequirePalletManagement || model.ServiceType == ServiceType.HaveCompany);

                                            #region Validations

                                            // Check company does not exist by Company Name & Registration Number
                                            if (isClient && !string.IsNullOrEmpty(model.CompanyRegistrationNumber) && cservice.ExistByCompanyRegistrationNumber(model.CompanyRegistrationNumber.Trim()))
                                            {
                                                Notify($"A Client with that Company Registration Number already exists. Contact us if you require further assistance.", NotificationType.Error);

                                                return(View(model));
                                            }
                                            else if (!isClient && !string.IsNullOrEmpty(model.CompanyRegistrationNumber) && pservice.ExistByCompanyRegistrationNumber(model.CompanyRegistrationNumber.Trim()))
                                            {
                                                Notify($"A Pooling Service Provider (PSP) with that Company Registration Number already exists. Contact us if you require further assistance.", NotificationType.Error);

                                                return(View(model));
                                            }

                                            #endregion

                                            RoleType roleType = (isClient) ? RoleType.Client : RoleType.PSP;

                                            user = new User()
                                            {
                                                Type    = ( int )roleType,
                                                Name    = model.CompanyName,
                                                Email   = model.AdminEmail,
                                                Cell    = model.ContactNumber,
                                                Surname = model.CompanyName,
                                                Status  = ( int )Status.Pending,
                                            };

                                            // Get Role
                                            Role role = rservice.GetByName(roleType.GetStringValue());

                                            if (isClient)
                                            {
                                                #region Create Client

                                                client = new Client()
                                                {
                                                    PSPName                   = model.PSPName,
                                                    Email                     = model.EmailAddress,
                                                    TradingAs                 = model.TradingAs,
                                                    VATNumber                 = model.VATNumber,
                                                    BBBEELevel                = model.BBBEELevel,
                                                    AdminEmail                = model.AdminEmail,
                                                    CompanyName               = model.CompanyName,
                                                    Description               = model.Description,
                                                    AdminPerson               = model.ContactPerson,
                                                    FinPersonEmail            = model.EmailAddress,
                                                    ContactPerson             = model.ContactPerson,
                                                    ContactNumber             = model.ContactNumber,
                                                    FinancialPerson           = model.ContactPerson,
                                                    CompanyType               = ( int )model.CompanyType,
                                                    PalletType                = ( int )model.TypeOfPalletUse,
                                                    Status                    = ( int )PSPClientStatus.Unverified,
                                                    ServiceRequired           = ( int )model.ServiceType,
                                                    PalletTypeOther           = model.OtherTypeOfPalletUse,
                                                    NumberOfLostPallets       = model.NumberOfLostPallets,
                                                    CompanyRegistrationNumber = model.CompanyRegistrationNumber,
                                                };

                                                if (model.PSPId > 0)
                                                {
                                                    client.PSPClients.Add(new PSPClient()
                                                    {
                                                        ClientId   = client.Id,
                                                        CreatedOn  = DateTime.Now,
                                                        PSPId      = model.PSPId.Value,
                                                        ModifiedOn = DateTime.Now,
                                                        ModifiedBy = model.AdminEmail,
                                                        Status     = ( int )Status.Active,
                                                    });
                                                }

                                                client = cservice.Create(client);

                                                user.ClientUsers.Add(new ClientUser()
                                                {
                                                    UserId     = user.Id,
                                                    ClientId   = client.Id,
                                                    CreatedOn  = DateTime.Now,
                                                    ModifiedOn = DateTime.Now,
                                                    ModifiedBy = model.AdminEmail,
                                                    Status     = ( int )Status.Active,
                                                });

                                                objectId   = client.Id;
                                                objectType = "Client";

                                                #endregion
                                            }
                                            else
                                            {
                                                #region Create PSP

                                                psp = new PSP()
                                                {
                                                    Email                     = model.EmailAddress,
                                                    TradingAs                 = model.TradingAs,
                                                    VATNumber                 = model.VATNumber,
                                                    BBBEELevel                = model.BBBEELevel,
                                                    AdminEmail                = model.AdminEmail,
                                                    CompanyName               = model.CompanyName,
                                                    Description               = model.Description,
                                                    AdminPerson               = model.ContactPerson,
                                                    ContactPerson             = model.ContactPerson,
                                                    ContactNumber             = model.ContactNumber,
                                                    FinPersonEmail            = model.EmailAddress,
                                                    FinancialPerson           = model.ContactPerson,
                                                    CompanyType               = ( int )model.CompanyType,
                                                    PalletType                = ( int )model.TypeOfPalletUse,
                                                    Status                    = ( int )PSPClientStatus.Unverified,
                                                    ServiceRequired           = ( int )model.ServiceType,
                                                    PalletTypeOther           = model.OtherTypeOfPalletUse,
                                                    NumberOfLostPallets       = model.NumberOfLostPallets,
                                                    CompanyRegistrationNumber = model.CompanyRegistrationNumber,
                                                };

                                                psp = pservice.Create(psp);

                                                user.PSPUsers.Add(new PSPUser()
                                                {
                                                    PSPId      = psp.Id,
                                                    UserId     = user.Id,
                                                    CreatedOn  = DateTime.Now,
                                                    ModifiedOn = DateTime.Now,
                                                    ModifiedBy = model.AdminEmail,
                                                    Status     = ( int )Status.Active,
                                                });

                                                objectId   = psp.Id;
                                                objectType = "PSP";

                                                #endregion
                                            }

                                            model.Id = objectId;

                                            #region Create User

                                            user = uservice.Create(user, role.Id);

                                            #endregion


                                            #region Create Estimated Load

                                            if (model.EstimatedLoad != null)
                                            {
                                                EstimatedLoad load = new EstimatedLoad()
                                                {
                                                    ObjectId   = objectId,
                                                    ObjectType = objectType,
                                                    BudgetYear = model.EstimatedLoad.BudgetYear,
                                                    January    = model.EstimatedLoad.January,
                                                    February   = model.EstimatedLoad.February,
                                                    March      = model.EstimatedLoad.March,
                                                    April      = model.EstimatedLoad.April,
                                                    May        = model.EstimatedLoad.May,
                                                    June       = model.EstimatedLoad.June,
                                                    July       = model.EstimatedLoad.July,
                                                    August     = model.EstimatedLoad.August,
                                                    September  = model.EstimatedLoad.September,
                                                    October    = model.EstimatedLoad.October,
                                                    November   = model.EstimatedLoad.November,
                                                    December   = model.EstimatedLoad.December,
                                                    Total      = model.EstimatedLoad.Total,
                                                };

                                                load = eservice.Create(load);
                                            }

                                            #endregion


                                            #region Create Address (s)

                                            if (model.Address != null)
                                            {
                                                Address address = new Address()
                                                {
                                                    ObjectId     = objectId,
                                                    ObjectType   = objectType,
                                                    Town         = model.Address.Town,
                                                    Status       = ( int )Status.Active,
                                                    PostalCode   = model.Address.PostCode,
                                                    Type         = ( int )model.Address.AddressType,
                                                    Addressline1 = model.Address.AddressLine1,
                                                    Addressline2 = model.Address.AddressLine2,
                                                    ProvinceId   = model.Address.ProvinceId,
                                                };

                                                aservice.Create(address);
                                            }

                                            #endregion


                                            #region Any Uploads

                                            if (model.Files.NullableAny(f => f.File != null))
                                            {
                                                // Create folder
                                                string path = Server.MapPath($"~/{VariableExtension.SystemRules.DocumentsLocation}/{objectType}/{model.CompanyName.Trim()}-{model.CompanyRegistrationNumber.Trim().Replace( "/", "_" ).Replace( "\\", "_" )}/");

                                                if (!Directory.Exists(path))
                                                {
                                                    Directory.CreateDirectory(path);
                                                }

                                                string now = DateTime.Now.ToString("yyyyMMddHHmmss");

                                                foreach (FileViewModel f in model.Files.Where(f => f.File != null))
                                                {
                                                    Document doc = new Document()
                                                    {
                                                        ObjectId    = objectId,
                                                        ObjectType  = objectType,
                                                        Status      = ( int )Status.Active,
                                                        Name        = f.Name,
                                                        Category    = f.Name,
                                                        Title       = f.File.FileName,
                                                        Size        = f.File.ContentLength,
                                                        Description = f.Description,
                                                        Type        = Path.GetExtension(f.File.FileName),
                                                        Location    = $"{objectType}/{model.CompanyName.Trim()}-{model.CompanyRegistrationNumber.Trim().Replace( "/", "_" ).Replace( "\\", "_" )}/{now}-{f.File.FileName}"
                                                    };

                                                    dservice.Create(doc);

                                                    string fullpath = Path.Combine(path, $"{now}-{f.File.FileName}");

                                                    try
                                                    {
                                                        f.File.SaveAs(fullpath);
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                    }
                                                }
                                            }

                                            #endregion

                                            // Complete the scope
                                            scope.Complete();
                                        }

            // Send Welcome Email
            bool sent = SendUserWelcome(model);

            if (sent)
            {
                SendUserWelcome1(model);
            }

            Notify("Thank you for your application to register, you will receive an email with further instructions shortly. Please check your spam folder if you do not receive mail within 24 hours.", NotificationType.Success);

            return(RedirectToAction("Login"));
        }