protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_userManager != null)
                {
                    _userManager.Dispose();
                    _userManager = null;
                }

                if (_signInManager != null)
                {
                    _signInManager.Dispose();
                    _signInManager = null;
                }

                if (_roleManager != null)
                {
                    _roleManager.Dispose();
                    _roleManager = null;
                }
                if (_logger != null)
                {
                    _logger.Dispose();
                    _logger = null;
                }
                if (_smtp != null)
                {
                    _smtp.Dispose();
                    _smtp = null;
                }
            }

            base.Dispose(disposing);
        }
 public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager, ApplicationRoleManager roleManager, CoreLoggerProvider logger, SMTPProvider smtp)
 {
     UserManager   = userManager;
     SignInManager = signInManager;
     RoleManager   = roleManager;
     Logger        = logger;
 }
 public BusinessAdminController(ApplicationUserManager userManager, ApplicationSignInManager signInManager, ApplicationRoleManager roleManager, CoreLoggerProvider logger, SMTPProvider smtp, BusinessProvider provider)
 {
     UserManager   = userManager;
     SignInManager = signInManager;
     RoleManager   = roleManager;
     Logger        = logger;
     Provider      = provider;
 }
        public async Task <MethodResults> AddUserToAccount(string userId, string emailAddress, string userName, CoreLoggerProvider logger, string IPAddress, string instigator, BPMainContext context, int accountId, int loginTypeId, int presidenceTypeId)
        {
            var methodResults = new MethodResults {
                Success = false, Message = "Something went wrong.  Nothing was changed.  Please try again or contact your network or system administrator."
            };
            // we're adding a user to either an existing account, or to a new account
            var account = new BPAccount();

            if (accountId == 0)
            {
                var dateType = await context.AccountDateTypes.FirstOrDefaultAsync(x => x.Index == 1);

                var accountType = await context.AccountTypes.FirstOrDefaultAsync(x => x.Index == 1);

                var accountDates = new List <AccountDate> {
                    new AccountDate {
                        DateLine = DateTimeOffset.Now, AccountDateType = dateType
                    }
                };

                account.EntityAttribute = new EntityAttribute
                {
                    AccountDates = accountDates,
                    AccountType  = accountType
                };
                account.UserAttribute = new UserAttribute();
            }
            else
            {
                account = await context.Accounts.FindAsync(accountId);
            }
            var loginType = await context.LoginIdTypes.FirstOrDefaultAsync(x => x.Index == loginTypeId);

            var presidenceType = await context.PresidenceTypes.FirstOrDefaultAsync(x => x.Index == presidenceTypeId);

            var loginIds = new List <LoginId> {
                new LoginId {
                    UserId         = userId,
                    EmailAddress   = emailAddress,
                    PresidenceType = presidenceType,
                    LoginIdType    = loginType
                }
            };
            var loginAttribute = new LoginAttribute
            {
                LoginIds = loginIds
            };

            if (accountId > 0)
            {
                var entry = context.Entry(account);
                entry.Entity.LoginAttribute = loginAttribute;
                entry.State = EntityState.Modified;
            }
            else
            {
                account.LoginAttribute = loginAttribute;
                context.Accounts.Add(account);
            }
            methodResults = await context.SaveChangesAsync(context);

            var subject = "Add user to account";
            var system  = "User Service";

            if (methodResults.Success)
            {
                await logger.CreateNewLog($"Successfully added user {emailAddress} to account {account.ID} on {IPAddress} by {instigator}.", subject, instigator, system);
            }
            else
            {
                await logger.CreateNewLog($"Unable to add user {emailAddress} to an account on {IPAddress} by {instigator}.", subject, instigator, system);
            }
            return(methodResults);
        }
Exemple #5
0
        public async Task <MethodResults> CreateNewBusiness(BusinessPullModel pullModel, BPMainContext context, string IPAddress, string instigator, CoreLoggerProvider logger)
        {
            var methodResults = new MethodResults {
                Success = false, Message = "Something went wrong.  Please try again, or contact your system administrator."
            };

            // the pull model should have been validated at the controller
            // first, create the account
            var account = new BPAccount()
            {
                BusinessAttribute = new BusinessAttribute(),
                EntityAttribute   = new EntityAttribute()
            };

            account.BusinessAttribute.BusinessName = pullModel.BusinessName;
            var subject = "Business Account Creation";
            var system  = "Business Service";

            account.EntityAttribute.AccountType = await context.AccountTypes.FirstOrDefaultAsync(x => x.Index == 2);

            account.BusinessAttribute.BusinessType = await context.BusinessTypes.FirstOrDefaultAsync(x => x.Index == pullModel.BusinessTypeId);

            var accountDateType = await context.AccountDateTypes.FirstOrDefaultAsync(x => x.Index == 1);

            var accountDate = new AccountDate {
                AccountDateType = accountDateType,
                DateLine        = DateTimeOffset.Now
            };

            account.EntityAttribute.AccountDates.Add(accountDate);

            context.Accounts.Add(account);

            methodResults = await context.SaveChangesAsync(context);

            if (methodResults.Success)
            {
                await logger.CreateNewLog($"Successfully create {pullModel.BusinessName} as {pullModel.BusinessTypes.FirstOrDefault(x => x.Value == pullModel.BusinessTypeId.ToString())} by {instigator} on {IPAddress}", subject, instigator, system);
            }
            else
            {
                await logger.CreateNewLog($"Failed to create new business {pullModel.BusinessName} by {instigator} on {IPAddress}", subject, instigator, system);
            }
            return(methodResults);
        }
Exemple #6
0
        public async Task <MethodResults> RemoveBusinessAccount(int id, BPMainContext context, CoreLoggerProvider logger, string IPAddress, string instigator)
        {
            // we're removing this business from the website
            var account = await context.Accounts.FindAsync(id);

            if (account == null)
            {
                return new MethodResults {
                           Success = false, Message = "This business could not be deleted because it could not be found."
                }
            }
            ;
            var subject      = "Account removal";
            var system       = "Business Service";
            var businessName = account.BusinessAttribute.BusinessName;

            if (account.LoginAttribute != null)
            {
                context.LoginAttributes.Remove(account.LoginAttribute);
            }
            if (account.EntityAttribute != null)
            {
                context.EntityAttributes.Remove(account.EntityAttribute);
            }
            if (account.BusinessAttribute != null)
            {
                context.BusinessAttributes.Remove(account.BusinessAttribute);
            }
            if (account.UserAttribute != null)
            {
                context.UserAttributes.Remove(account.UserAttribute);
            }
            context.Accounts.Remove(account);
            var returnResults = await context.SaveChangesAsync(context);

            if (returnResults.Success)
            {
                await logger.CreateNewLog($"Business account {businessName} successfully removed by {instigator} on {IPAddress}", subject, instigator, system);
            }
            else
            {
                await logger.CreateNewLog($"Could not remove business account {businessName} by {instigator} on {IPAddress}", subject, instigator, system);
            }
            return(returnResults);
        }