Пример #1
0
        public ActionResult About()
        {
            //Utilities.LogAppError("Test exception.");

            try
            {
                //new MailController().SendPasswordResetEmail(User.Identity.Name, "SampleResetLink").Deliver();
                //new MailController().SendSignUpEmail(User.Identity.Name).Deliver();

                IList <MenuAndLink> menus = new List <MenuAndLink>();
                MenuAndLink         item  = new MenuAndLink();
                item.MenuName = "Bob's Cafe";
                item.MenuLink = "http://www.BobCafe.com";
                menus.Add(item);
                //MenuAndLink item2 = new MenuAndLink();
                //item2.MenuName = "Depot";
                //item2.MenuLink = "http://www.depot.com";
                //menus.Add(item2);
                IList <MenuAndLink> menus2 = new List <MenuAndLink>();
                new MailController().SendDeactivateEmail(User.Identity.Name, 0, menus2, menus).Deliver();
            }
            catch
            {
            }

            return(View());
        }
Пример #2
0
/*
 *      private bool ActivateMenu(int id, Menu menu, string email, int quantity)
 *      {
 *          //set menu as active
 *          menu.Active = true;
 *
 *          V1 composer = new V1(menu);
 *          // re-compose the menu
 *          string fullURL = composer.CreateMenu();
 *
 *          db.Entry(menu).State = EntityState.Modified;
 *
 *          //for confirmation email
 *          IList<MenuAndLink> justActivatedMenusAndLinks = new List<MenuAndLink>();
 *          IList<MenuAndLink> totalActivatedMenusAndLinks = new List<MenuAndLink>();
 *
 *          MenuAndLink item = new MenuAndLink();
 *          item.MenuName = menu.Name;
 *          item.MenuLink = fullURL;
 *          justActivatedMenusAndLinks.Add(item);
 *
 *          //get total list of activated menus
 *          IOrderedQueryable<Menu> allMenus = Utilities.GetAllMenus(email, db);
 *          if (allMenus == null) { return false; }
 *
 *          foreach (Menu singleMenu in allMenus)
 *          {
 *              item = new MenuAndLink();
 *              item.MenuName = singleMenu.Name;
 *              item.MenuLink = Utilities.GetFullUrl(singleMenu.MenuDartUrl);
 *
 *              if (singleMenu.Active)
 *              {
 *                  totalActivatedMenusAndLinks.Add(item);
 *              }
 *          }
 *
 *          //send confirmation email to user
 *          try //TODO: remove for Production SMTP
 *          {
 *              new MailController().SendActivateEmail(email, quantity * Constants.CostPerMenu, justActivatedMenusAndLinks, totalActivatedMenusAndLinks).Deliver();
 *          }
 *          catch
 *          {
 *          }
 *
 *          return true;
 *      }
 */
        private bool DeactivateMenu(int id, Menu menu, string email, int quantity)
        {
            //set menu as deactivated
            menu.Active = false;

            //deactivate the menu directory (delete menu but not logo file)
            Utilities.DeactivateDirectory(menu.MenuDartUrl);

            db.Entry(menu).State = EntityState.Modified;

            //get status of all menus this owner has
            IOrderedQueryable <Menu> allMenus = Utilities.GetAllMenus(email, db);

            if (allMenus == null)
            {
                return(false);
            }

            //list of menu names and links for confirmation email
            IList <MenuAndLink> remainingActiveMenusAndLinks = new List <MenuAndLink>();
            IList <MenuAndLink> deactivatedMenusAndLinks     = new List <MenuAndLink>();

            foreach (Menu singleMenu in allMenus)
            {
                MenuAndLink item = new MenuAndLink();
                item.MenuName = singleMenu.Name;
                item.MenuLink = Utilities.GetFullUrl(singleMenu.MenuDartUrl);

                if (singleMenu.Active)
                {
                    remainingActiveMenusAndLinks.Add(item);
                }
                else
                {
                    deactivatedMenusAndLinks.Add(item);
                }
            }

            //send confirmation email to user
            try //TODO: remove for Production SMTP
            {
                new MailController().SendDeactivateEmail(email, quantity * Constants.CostPerMenu, remainingActiveMenusAndLinks, deactivatedMenusAndLinks).Deliver();
            }
            catch
            {
            }

            return(true);
        }
Пример #3
0
        private bool ActivateAllMenus(string email, int quantity)
        {
            //set all menu(s) this owner has as active
            IOrderedQueryable <Menu> allMenus = Utilities.GetAllMenus(email, db);

            if (allMenus == null)
            {
                return(false);
            }

            //list of menu names and links for confirmation email
            IList <MenuAndLink> justActivatedMenusAndLinks = new List <MenuAndLink>();
            //not used by view when all menus are activated, so just keep empty
            IList <MenuAndLink> totalActivatedMenusAndLinks = new List <MenuAndLink>();

            foreach (Menu singleMenu in allMenus)
            {
                //set menu as active
                singleMenu.Active = true;

                V1 composer = new V1(singleMenu);
                // re-compose the menu
                string fullURL = composer.CreateMenu();

                db.Entry(singleMenu).State = EntityState.Modified;

                //info for confirmation email
                MenuAndLink item = new MenuAndLink();
                item.MenuName = singleMenu.Name;
                item.MenuLink = fullURL;
                justActivatedMenusAndLinks.Add(item);
            }

            //send confirmation email to user
            try //TODO: remove for Production SMTP
            {
                new MailController().SendActivateEmail(email, quantity * Constants.CostPerMenu, justActivatedMenusAndLinks, totalActivatedMenusAndLinks).Deliver();
            }
            catch
            {
            }

            return(true);
        }
Пример #4
0
        private bool DeactivateAllMenus(string email)
        {
            //set all menu(s) this owner has as inactive
            IOrderedQueryable <Menu> allMenus = Utilities.GetAllMenus(email, db);

            if (allMenus == null)
            {
                return(false);
            }

            //list of menu names and links for confirmation email
            //remaining active menus will be empty since we're deactivating all
            IList <MenuAndLink> remainingActiveMenusAndLinks = new List <MenuAndLink>();
            IList <MenuAndLink> deactivatedMenusAndLinks     = new List <MenuAndLink>();

            foreach (Menu singleMenu in allMenus)
            {
                //set menu as deactivated
                singleMenu.Active = false;

                //deactivate the menu directory (delete menu but not logo file)
                Utilities.DeactivateDirectory(singleMenu.MenuDartUrl);

                db.Entry(singleMenu).State = EntityState.Modified;

                //info for confirmation email
                MenuAndLink item = new MenuAndLink();
                item.MenuName = singleMenu.Name;
                item.MenuLink = Utilities.GetFullUrl(singleMenu.MenuDartUrl);
                deactivatedMenusAndLinks.Add(item);
            }

            //send confirmation email to user
            try //TODO: remove for Production SMTP
            {
                new MailController().SendDeactivateEmail(email, 0, remainingActiveMenusAndLinks, deactivatedMenusAndLinks).Deliver();
            }
            catch
            {
            }

            return(true);
        }
Пример #5
0
        public static bool ActivateMenu(int id, Menu menu, string email, int quantity, MenuDartDBContext db, bool isTrial)
        {
            //set menu as active
            menu.Active = true;

            V1 composer = new V1(menu);
            // re-compose the menu
            string fullURL = composer.CreateMenu();

            db.Entry(menu).State = EntityState.Modified;

            //for confirmation email
            IList <MenuAndLink> justActivatedMenusAndLinks  = new List <MenuAndLink>();
            IList <MenuAndLink> totalActivatedMenusAndLinks = new List <MenuAndLink>();

            MenuAndLink item = new MenuAndLink();

            item.MenuName = menu.Name;
            item.MenuLink = fullURL;
            justActivatedMenusAndLinks.Add(item);

            //get total list of activated menus
            IOrderedQueryable <Menu> allMenus = Utilities.GetAllMenus(email, db);

            if (allMenus == null)
            {
                return(false);
            }

            foreach (Menu singleMenu in allMenus)
            {
                item          = new MenuAndLink();
                item.MenuName = singleMenu.Name;
                item.MenuLink = Utilities.GetFullUrl(singleMenu.MenuDartUrl);

                if (singleMenu.Active)
                {
                    totalActivatedMenusAndLinks.Add(item);
                }
            }

            //send confirmation email to user
            if (isTrial)
            {
                try //TODO: remove for Production SMTP
                {
                    new MailController().SendActivateEmailTrial(email, justActivatedMenusAndLinks).Deliver();
                }
                catch
                {
                }
            }
            else
            {
                try //TODO: remove for Production SMTP
                {
                    new MailController().SendActivateEmail(email, quantity * Constants.CostPerMenu, justActivatedMenusAndLinks, totalActivatedMenusAndLinks).Deliver();
                }
                catch
                {
                }
            }

            return(true);
        }
Пример #6
0
        private void CheckForExpiredTrials()
        {
            IList <UserInfo> userList = GetAllUsersOnTrial();

            if (userList != null)
            {
                foreach (UserInfo user in userList)
                {
                    MembershipUser currentUser = null;

                    try
                    {
                        currentUser = Membership.GetUser(user.Name);
                    }
                    catch (Exception e)
                    {
                        Utilities.LogAppError("Could not retrieve user account.", e);
                    }

                    if (currentUser != null)
                    {
                        //check if trial period has expired (30 days from user account creation)
                        TimeSpan diff = DateTime.Today - currentUser.CreationDate.Date;

                        if (diff.Days >= Constants.TrialPeriodDays)
                        {
                            user.TrialEnded      = true;
                            db.Entry(user).State = EntityState.Modified;

                            //deactivate menus if not subscribed
                            if (!user.Subscribed)
                            {
                                //list of menu names and links for confirmation email
                                IList <MenuAndLink> deactivatedMenusAndLinks = new List <MenuAndLink>();

                                //set all menu(s) this owner has as inactive
                                IOrderedQueryable <Menu> allMenus = Utilities.GetAllMenus(user.Name, db);

                                if (allMenus != null)
                                {
                                    foreach (Menu singleMenu in allMenus)
                                    {
                                        //set menu as deactivated
                                        singleMenu.Active = false;

                                        //deactivate the menu directory (delete menu but not logo file)
                                        Utilities.DeactivateDirectory(singleMenu.MenuDartUrl);

                                        db.Entry(singleMenu).State = EntityState.Modified;

                                        //info for confirmation email
                                        MenuAndLink item = new MenuAndLink();
                                        item.MenuName = singleMenu.Name;
                                        item.MenuLink = Utilities.GetFullUrl(singleMenu.MenuDartUrl);
                                        deactivatedMenusAndLinks.Add(item);
                                    }
                                }

                                //send confirmation email to user
                                try //TODO: remove for Production SMTP
                                {
                                    new MailController().SendTrialExpiredEmail(user.Name, deactivatedMenusAndLinks).Deliver();
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }

                //save all changes to DB
                db.SaveChanges();
            }
        }
Пример #7
0
        private void WarnUpcomingExpiringTrials()
        {
            IList <UserInfo> userList = GetAllUsersOnTrial();

            if (userList != null)
            {
                foreach (UserInfo user in userList)
                {
                    MembershipUser currentUser = null;

                    try
                    {
                        currentUser = Membership.GetUser(user.Name);
                    }
                    catch (Exception e)
                    {
                        Utilities.LogAppError("Could not retrieve user account.", e);
                    }

                    if (currentUser != null)
                    {
                        //check if trial period is nearing expiration
                        TimeSpan diff = DateTime.Today - currentUser.CreationDate.Date;

                        if (diff.Days >= Constants.TrialExpWarningDays)
                        {
                            //send warning email if user hasn't subscribed yet
                            if (!user.Subscribed && !user.TrialExpWarningSent)
                            {
                                //list of menu names and links for confirmation email
                                IList <MenuAndLink> deactivatedMenusAndLinks = new List <MenuAndLink>();

                                //find all user's menus that are in danger of being deactivated
                                IOrderedQueryable <Menu> allMenus = Utilities.GetAllMenus(user.Name, db);

                                if (allMenus != null)
                                {
                                    foreach (Menu singleMenu in allMenus)
                                    {
                                        //info for confirmation email
                                        MenuAndLink item = new MenuAndLink();
                                        item.MenuName = singleMenu.Name;
                                        item.MenuLink = Utilities.GetFullUrl(singleMenu.MenuDartUrl);
                                        deactivatedMenusAndLinks.Add(item);
                                    }
                                }

                                //send warning email to user
                                try //TODO: remove for Production SMTP
                                {
                                    new MailController().SendTrialWarningEmail(user.Name, deactivatedMenusAndLinks).Deliver();

                                    //flag that we've sent a warning email already
                                    user.TrialExpWarningSent = true;
                                    db.Entry(user).State     = EntityState.Modified;
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }

                //save all changes to DB
                db.SaveChanges();
            }
        }