public ActionResult Edit(TempMenu tempmenu) { if (ModelState.IsValid) { db.Entry(tempmenu).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tempmenu)); }
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)); }
/* * 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); }
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 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); }
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(); } }