Exemple #1
0
        public bool AddPackageHistory(AddPackageHistoryDto packageHistoryInfo)
        {
            var franchisee = _franchiseeTenantRepository.FirstOrDefault(
                o => o.Name == packageHistoryInfo.FranchiseeName && o.LicenseKey == packageHistoryInfo.LicenseKey);
            var packageHistory = new PackageHistory();

            using (var scope = new TransactionScope())
            {
                packageHistory.PackageId          = packageHistoryInfo.PackageId;
                packageHistory.OldPackageId       = packageHistoryInfo.OldPackageId;
                packageHistory.StartDate          = packageHistoryInfo.StartDate;
                packageHistory.EndDate            = packageHistoryInfo.EndDate;
                packageHistory.RequestId          = packageHistoryInfo.RequestId;
                packageHistory.FranchiseeTenantId = packageHistoryInfo.FranchiseeTenantId;
                packageHistory.AccountNumber      = packageHistoryInfo.AccountNumber;
                packageHistory.IsApply            = packageHistoryInfo.IsApply;
                Add(packageHistory);

                if (!packageHistoryInfo.IsApply)
                {
                    franchisee.EndActiveDate = packageHistoryInfo.StartDate;
                }
                if (packageHistoryInfo.IsApply)
                {
                    franchisee.CurrentPackageId = packageHistoryInfo.PackageId;
                    franchisee.EndActiveDate    = packageHistoryInfo.EndDate;
                }

                franchisee.RemainingAmount        = packageHistoryInfo.Amount;
                franchisee.NextBillingDate        = packageHistoryInfo.NextBillingDate;
                franchisee.PackageNextBillingDate = packageHistoryInfo.PackageNextBillingDate;
                franchisee.StartDateSuccess       = null;
                franchisee.EndDateSuccess         = null;
                _franchiseeTenantRepository.Update(franchisee);
                _franchiseeTenantRepository.Commit();

                scope.Complete();
                return(true);
            }
        }
Exemple #2
0
        public int SetupFranchisee(FranchiseeTenant franchiseeTenant, FranchiseeConfiguration franchiseeConfiguration)
        {
            using (var scope = new TransactionScope())
            {
                //Add Franchise
                ValidateBusinessRules(franchiseeTenant);
                _franchiseeTenantRepository.Add(franchiseeTenant);
                _franchiseeTenantRepository.Commit();
                int i = 0;
                var connectionString = PersistenceHelper.GenerateConnectionString(franchiseeTenant.Server,
                                                                                  franchiseeTenant.Database, franchiseeTenant.UserName, franchiseeTenant.Password);
                var database = franchiseeTenant.Database;

                // Create franchisee configuaration
                // Check franchisee configuaration has exists
                #region
                _franchiseeConfigurationRepository.DeleteAllFranchiseeConfigurationBySqlString(database);

                var franchiseeId             = PasswordHelper.HashString(franchiseeTenant.Id.ToString(), franchiseeTenant.Name);
                var licenseKey               = franchiseeTenant.LicenseKey;
                var franchiseeContact        = franchiseeConfiguration.FranchiseeContact;
                var primaryContactPhone      = franchiseeConfiguration.PrimaryContactPhone;
                var primaryContactEmail      = franchiseeConfiguration.PrimaryContactEmail;
                var primaryContactFax        = franchiseeConfiguration.PrimaryContactFax;
                var primaryContactCellNumber = franchiseeConfiguration.PrimaryContactCellNumber;
                var name        = franchiseeConfiguration.Name;
                var city        = franchiseeConfiguration.City;
                var state       = franchiseeConfiguration.State;
                var zip         = franchiseeConfiguration.Zip;
                var address1    = franchiseeConfiguration.Address1;
                var address2    = franchiseeConfiguration.Address2;
                var officePhone = franchiseeConfiguration.OfficePhone;
                var faxNumber   = franchiseeConfiguration.FaxNumber;
                var industryId  = franchiseeConfiguration.IndustryId;
                var logo        = franchiseeConfiguration.Logo;

                var franchiseeconfig = new FranchiseeConfiguration
                {
                    FranchiseeId             = franchiseeId,
                    LicenseKey               = licenseKey,
                    FranchiseeContact        = franchiseeContact,
                    PrimaryContactPhone      = primaryContactPhone,
                    PrimaryContactEmail      = primaryContactEmail,
                    PrimaryContactFax        = primaryContactFax,
                    PrimaryContactCellNumber = primaryContactCellNumber,
                    Name        = name,
                    City        = city,
                    State       = state,
                    Zip         = zip,
                    Address1    = address1,
                    Address2    = address2,
                    OfficePhone = officePhone,
                    FaxNumber   = faxNumber,
                    Logo        = logo,
                    IndustryId  = industryId
                };
                _franchiseeConfigurationRepository.AddFranchiseeConfigurationBySqlString(franchiseeconfig, database);
                #endregion

                // Create a franchisee admin role
                #region

                _userRoleRepository.ChangeConnectionString(connectionString);

                var franchiseeAdminRole   = _userRoleRepository.FirstOrDefault(o => o.AppRoleName == AppRole.GlobalAdmin.ToString());
                var idFranchiseeAdminRole = 0;
                if (franchiseeAdminRole == null)
                {
                    // Create franchisee admin role
                    var franchiseeAdminRoleAdd = new UserRole
                    {
                        Name              = "Franchisee Admin",
                        AppRoleName       = AppRole.GlobalAdmin.ToString(),
                        UserRoleFunctions = new List <UserRoleFunction>()
                    };
                    // Create list userRoleFunction for franchisee admin
                    var objListDocumentType = _userRoleRepository.GetAllDocumentType();
                    foreach (var documentType in objListDocumentType)
                    {
                        var objViewAdd = new UserRoleFunction
                        {
                            DocumentTypeId      = documentType.Id,
                            SecurityOperationId = (int)OperationAction.View
                        };
                        franchiseeAdminRoleAdd.UserRoleFunctions.Add(objViewAdd);

                        //Implement View insert
                        var objInsertAdd = new UserRoleFunction
                        {
                            DocumentTypeId      = documentType.Id,
                            SecurityOperationId = (int)OperationAction.Add,
                        };
                        franchiseeAdminRoleAdd.UserRoleFunctions.Add(objInsertAdd);

                        //Implement View update
                        var objUpdateAdd = new UserRoleFunction
                        {
                            DocumentTypeId      = documentType.Id,
                            SecurityOperationId = (int)OperationAction.Update,
                        };
                        franchiseeAdminRoleAdd.UserRoleFunctions.Add(objUpdateAdd);
                        //Implement View delete
                        var objDeleteAdd = new UserRoleFunction
                        {
                            DocumentTypeId      = documentType.Id,
                            SecurityOperationId = (int)OperationAction.Delete,
                        };
                        franchiseeAdminRoleAdd.UserRoleFunctions.Add(objDeleteAdd);

                        var objProcessAdd = new UserRoleFunction
                        {
                            DocumentTypeId      = documentType.Id,
                            SecurityOperationId = (int)OperationAction.Process,
                        };
                        franchiseeAdminRoleAdd.UserRoleFunctions.Add(objProcessAdd);
                    }
                    _userRoleRepository.Add(franchiseeAdminRoleAdd);
                    _userRoleRepository.Commit();
                    idFranchiseeAdminRole = franchiseeAdminRoleAdd.Id;
                }
                else
                {
                    idFranchiseeAdminRole = franchiseeAdminRole.Id;
                }
                #endregion

                // Create franchisee admin user
                // Check user admin has exists
                #region
                _userRepository.ChangeConnectionString(connectionString);
                var isExistsUserFranchiseeAdmin = _userRepository.CheckExist(o => o.UserRoleId == idFranchiseeAdminRole);
                if (!isExistsUserFranchiseeAdmin)
                {
                    var    randomPassword = "******";
                    string username       = franchiseeTenant.Name.Replace(" ", "");
                    var    password       = PasswordHelper.HashString(randomPassword, username);
                    var    phoneNumber    = franchiseeConfiguration.PrimaryContactPhone;      // "1111111111";
                    var    email          = franchiseeConfiguration.PrimaryContactEmail;      //  "*****@*****.**";
                    var    cellPhone      = franchiseeConfiguration.PrimaryContactCellNumber; // "1111111111";

                    // Create user franchisee admin
                    var userFranchiseeAdmin = new User
                    {
                        UserName    = username,
                        Password    = password,
                        UserRoleId  = idFranchiseeAdminRole,
                        IsActive    = true,
                        FirstName   = "Admin",
                        LastName    = "Franchisee",
                        HomePhone   = phoneNumber,
                        MobilePhone = cellPhone,
                        Email       = email,
                    };
                    _userRepository.AddUserBySqlString(userFranchiseeAdmin, database);
                }
                #endregion
                scope.Complete();
                return(franchiseeTenant.Id);
            }
        }