public static bool IsThisMyMenu(int questionedMenuId, MenuDartDBContext db, IPrincipal User) { //check if admin role if (User.IsInRole("Administrator")) { return(true); } IOrderedQueryable <Menu> myMenus = from menu in db.Menus where menu.Owner == User.Identity.Name orderby menu.ID ascending select menu; if (myMenus == null) { return(false); } //check if we own this menu foreach (Menu menu in myMenus.ToList()) { if (menu.ID == questionedMenuId) { return(true); } } return(false); }
public static bool IsUserOnTrial(MenuDartDBContext db, IPrincipal User) { //retrieve user info entry IOrderedQueryable <UserInfo> userFound = from userInfo in db.UserInfo where userInfo.Name == User.Identity.Name orderby userInfo.Name ascending select userInfo; //if there is a user logged in if ((userFound == null) || (userFound.Count() == 0)) { return(false); } //should only be one in the list IList <UserInfo> userInfoList = userFound.ToList(); if (userInfoList[0].TrialEnded) { return(false); } else { return(true); } }
public static IOrderedQueryable <Menu> GetAllMenus(string owner, MenuDartDBContext db) { IOrderedQueryable <Menu> allMenus = from allMenu in db.Menus where allMenu.Owner == owner orderby allMenu.Name ascending select allMenu; if (allMenus == null) { Utilities.LogAppError("Could not retrieve all menus for owner: " + owner); } return(allMenus); }
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); }