Exemple #1
0
        /// <summary>
        /// This method checks changes the OwnerEnabled fields to the opposite
        /// of what they currently are. Activates or deactivates secondary account.
        /// This also updates the lastEdited property to current time.
        /// </summary>
        /// <param name="secondaryEmail"></param>
        /// <returns></returns>
        public static bool ModifySecondaryAccountStatus(string secondaryEmail)
        {
            try
            {
                using (var db = new AllStockedDBEntities())
                {
                    SecondaryAccountAccess secondaryAccountAccess = db.SecondaryAccountAccesses.Where(a => a.SecondaryAccountEmail == secondaryEmail).Single();
                    Account secondaryAccount = db.Accounts.Where(a => a.AccountID == secondaryAccountAccess.SecondaryAccountID).Single();

                    if (secondaryAccountAccess.OwnerEnabled == true)
                    {
                        secondaryAccountAccess.OwnerEnabled = false;
                        secondaryAccount.AccountType        = db.AccountTypes.First(a => a.TypeID == 1);
                    }
                    else
                    {
                        secondaryAccountAccess.OwnerEnabled = true;
                        secondaryAccount.AccountType        = db.AccountTypes.First(a => a.TypeID == 2);
                    }

                    secondaryAccountAccess.LastEdited = DateTime.Now;
                    db.SaveChanges();

                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
 //Turns model into View Model
 public SecondaryAccountAccessViewModel(SecondaryAccountAccess model)
 {
     SecondaryAccountID    = model.SecondaryAccountID;
     SecondaryAccountEmail = model.SecondaryAccountEmail;
     OwnerEmail            = model.OwnerEmail;
     LastEdited            = model.LastEdited;
     Status = model.getStatus();
 }
Exemple #3
0
        public static int GetAccountOwnerIdBySecondaryId(int secondaryId)
        {
            using (var db = new AllStockedDBEntities())
            {
                SecondaryAccountAccess accessAccount = db.SecondaryAccountAccesses.FirstOrDefault(a => a.SecondaryAccountID == secondaryId);

                return(accessAccount.OwnerAccountID);
            }
        }
Exemple #4
0
        public ActionResult CreateSecondaryAccountAccess(SecondaryAccountAccess secondaryAccountAccess)
        {
            string errorMessage = "";

            //Check to see if the account exists
            if (!DbHelper.DoesAccountExist(secondaryAccountAccess.SecondaryAccountEmail))
            {
                errorMessage = "Invalid Email";
            }
            // make sure the account isnt already a secondary account
            else if (DbHelper.IsAccountAlreadySecondary(secondaryAccountAccess.SecondaryAccountEmail))
            {
                errorMessage = "This Account is already a secondary account.";
            }
            else
            {
                secondaryAccountAccess.OwnerAccountID     = SessionHelper.GetAccountIdFromSession();
                secondaryAccountAccess.OwnerEmail         = DbHelper.GetEmailById(SessionHelper.GetAccountIdFromSession());
                secondaryAccountAccess.SecondaryAccountID = DbHelper.GetAccountIdByEmail(secondaryAccountAccess.SecondaryAccountEmail);
                secondaryAccountAccess.AccessToken        = DbHelper.RandomString();
                secondaryAccountAccess.OwnerEnabled       = true;
                secondaryAccountAccess.SecondaryEnabled   = false;
                secondaryAccountAccess.LastEdited         = DateTime.Now;

                using (var db = new AllStockedDBEntities())
                {
                    try
                    {
                        db.SecondaryAccountAccesses.Add(secondaryAccountAccess);
                        db.SaveChanges();

                        string senderName = DbHelper.GetAccountFullNameById(secondaryAccountAccess.OwnerAccountID);

                        // Sends email to requested account with the Access token to become secondary Account
                        // I am sending these emails to self for testing purposes.
                        //Debug
                        DbHelper.EmailSecondaryAccessRequest(senderName, Creds.EmailCreds(), secondaryAccountAccess.AccessToken);
                        //Production
                        //DbHelper.EmailSecondaryAccessRequest(senderName, secondaryAccountAccess.SecondaryAccountEmail,  secondaryAccountAccess.AccessToken);
                    }
                    catch
                    {
                        errorMessage = "Error processing your request";
                    }
                }
            }

            //Add Error Message
            if (!String.IsNullOrEmpty(errorMessage))
            {
                TempData["ErrorMessage"] = errorMessage;
            }

            return(RedirectToAction("Settings", "Settings"));
        }
Exemple #5
0
 /// <summary>
 /// Checks SecondaryAccountAccess table NOT Account.Type property
 /// important to check as to not make account secondary to multiple accounts
 /// </summary>
 /// <param name="secondaryEmail"></param>
 /// <returns></returns>
 public static bool IsAccountAlreadySecondary(string secondaryEmail)
 {
     try
     {
         using (var db = new AllStockedDBEntities())
         {
             SecondaryAccountAccess secondaryAccount = db.SecondaryAccountAccesses.Where(a => a.SecondaryAccountEmail == secondaryEmail).Single();
             if (secondaryAccount == null)
             {
                 return(false);
             }
             else
             {
                 return(true);
             }
         }
     }
     catch
     {
         return(false);
     }
 }