public ActionResult Create(TempMenu tempmenu)
        {
            if (ModelState.IsValid)
            {
                db.TempMenus.Add(tempmenu);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tempmenu));
        }
Beispiel #2
0
        public ActionResult Create(List <Location> locations, int id)
        {
            if (ModelState.IsValid)
            {
                Menu menu = db.Menus.Find(id);

                if (menu == null)
                {
                    return(HttpNotFound());
                }

                //first deserialize current locations
                List <Location> currentLocations = Composer.V1.DeserializeLocations(menu.Locations);

                if ((currentLocations != null) && (currentLocations.Count > 0))
                {
                    //add all locations to the current set
                    currentLocations.AddRange(locations);

                    //serialize back into the menu
                    menu.Locations = Composer.V1.SerializeLocations(currentLocations);
                }
                else
                {
                    //no current locations, so just set serialized data directly into menu
                    menu.Locations = Composer.V1.SerializeLocations(locations);
                }

                //save menu
                db.Entry(menu).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Details", "Menu", new { id = id }));
            }

            return(View(locations));
        }
        public ActionResult Create(MenuNode newMenuNode, int id, string parent)
        {
            if ((id == 0) || !Utilities.IsThisMyMenu(id, db, User))
            {
                return(RedirectToAction("MenuBuilderAccessViolation", "Menu"));
            }

            //we need a parent in order to know where to create these menu nodes
            if (!string.IsNullOrEmpty(parent))
            {
                if ((ModelState.IsValid) && (!string.IsNullOrEmpty(newMenuNode.Title)))
                {
                    Menu menu = db.Menus.Find(id);

                    if (menu == null)
                    {
                        Utilities.LogAppError("Could not find menu.");
                        return(HttpNotFound());
                    }

                    //first deserialize current menu tree
                    List <MenuNode> currentMenuTree = V1.DeserializeMenuTree(menu.MenuTree);

                    if ((currentMenuTree != null) && (currentMenuTree.Count > 0))
                    {
                        //if this is the root level
                        if (parent == Constants.RootLevel)
                        {
                            try
                            {
                                newMenuNode.Link = IncrementLink(currentMenuTree.Last(node => !(node is MenuLeaf)).Link);
                            }
                            catch //there is no other menuNode
                            {
                                newMenuNode.Link = FirstLink;
                            }

                            //add node to the root level
                            currentMenuTree.Add(newMenuNode);
                        }
                        else
                        {
                            //find the parent node
                            MenuNode parentNode = V1.FindMenuNode(currentMenuTree, parent);

                            if (parentNode != null)
                            {
                                try
                                {
                                    newMenuNode.Link = IncrementLink(parentNode.Branches.Last(node => !(node is MenuLeaf)).Link);
                                }
                                catch //there is no other menuNode
                                {
                                    //create the first category link of this level
                                    newMenuNode.Link = parentNode.Link + FirstLinkSuffix;
                                }

                                //add node to the parent's branches
                                parentNode.Branches.Add(newMenuNode);
                            }
                        }

                        //serialize back into the menu
                        menu.MenuTree = V1.SerializeMenuTree(currentMenuTree);
                    }
                    else
                    {
                        //this is the first and only node of the tree
                        newMenuNode.Link = FirstLink;

                        List <MenuNode> newMenuNodeList = new List <MenuNode>();
                        newMenuNodeList.Add(newMenuNode);

                        //no current nodes, so just set serialized data directly into menu
                        menu.MenuTree = V1.SerializeMenuTree(newMenuNodeList);
                    }

                    //mark menu as dirty
                    menu.ChangesUnpublished = true;

                    //save menu in DB
                    db.Entry(menu).State = EntityState.Modified;
                    db.SaveChanges();

                    return(RedirectToAction("Details", new { id = id, parent = parent, idx = -1 }));
                }

                //send it back to the form
                ViewBag.Parent = parent;
                ViewBag.MenuId = id;

                return(View(newMenuNode));
            }

            return(HttpNotFound());
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to create the user account
                MembershipCreateStatus createStatus;
                MembershipUser         creationInfo = Membership.CreateUser(model.Email, model.Password, model.Email, null, null, true, null, out createStatus);

                if (createStatus == MembershipCreateStatus.Success)
                {
                    //create user info entry
                    IOrderedQueryable <UserInfo> userFound = from userInfo in db.UserInfo
                                                             where userInfo.Name == model.Email
                                                             orderby userInfo.Name ascending
                                                             select userInfo;

                    if ((userFound == null) || (userFound.Count() == 0))
                    {
                        UserInfo newUserInfo = new UserInfo();
                        newUserInfo.Name                  = model.Email;
                        newUserInfo.Subscribed            = false;
                        newUserInfo.TrialEnded            = false;
                        newUserInfo.TrialExpWarningSent   = false;
                        newUserInfo.PaymentCustomerId     = string.Empty;
                        newUserInfo.PaymentCustomerStatus = string.Empty;

                        db.UserInfo.Add(newUserInfo);
                        db.SaveChanges();
                    }

                    //set temp menu to owner
                    MigrateSessionCart(model.Email);

                    FormsAuthentication.SetAuthCookie(model.Email, false /* createPersistentCookie */);

                    //Email welcome message to user
                    try //TODO: remove try/catch when using real SMTP server in production
                    {
                        new MailController().SendSignUpEmail(model.Email).Deliver();

                        //send to Support email, too
                        new MailController().NewUserNoticeEmail(model.Email).Deliver();
                    }
                    catch
                    {
                    }

                    if (!string.IsNullOrEmpty(model.ReturnAction) && !string.IsNullOrEmpty(model.ReturnController))
                    {
                        return(RedirectToAction(model.ReturnAction, model.ReturnController, new { id = model.ReturnMenuId }));
                    }
                    else
                    {
                        //send to Dashboard by default
                        return(RedirectToAction("Index", "Dashboard"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", ErrorCodeToString(createStatus));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #5
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();
            }
        }
Beispiel #6
0
        public ActionResult Activate(int id = 0)
        {
            if ((id == 0) || !Utilities.IsThisMyMenu(id, db, User))
            {
                return(RedirectToAction("MenuBuilderAccessViolation", "Menu"));
            }

            Menu menu = db.Menus.Find(id);

            if (menu == null)
            {
                Utilities.LogAppError("Could not find menu.");
                return(HttpNotFound());
            }

            //just activate the menu directly if user is on free trial
            if (Utilities.IsUserOnTrial(db, User))
            {
                if (!Utilities.ActivateMenu(id, menu, User.Identity.Name, 1, db, true))
                {
                    return(RedirectToAction("Failed"));
                }

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

                //for view display. Use TempData since we're
                //using RedirectToAction() as opposed to View()
                TempData["Id"]   = id;
                TempData["Name"] = menu.Name;
                TempData["Url"]  = Utilities.GetFullUrl(menu.MenuDartUrl);

                return(RedirectToAction("ActivateCompleted"));
            }

            //Else, continue w/ payment data collection...
            //find out how many active menus this owner already has
            IOrderedQueryable <Menu> allMenus = Utilities.GetAllMenus(menu.Owner, db);

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

            int activeCount = 0;

            foreach (Menu activeMenu in allMenus)
            {
                if (activeMenu.Active)
                {
                    activeCount++;
                }
            }

            //display to user what the new billing will be
            ViewBag.NumActiveMenus = activeCount + 1;
            ViewBag.NewTotal       = (activeCount + 1) * 7;
            ViewBag.Email          = menu.Owner;
            ViewBag.StripeKey      = Constants.StripePublishableKey;

            return(View(menu));
        }