Esempio n. 1
0
 private int UpdateMenuSection(MenuSectionViewModel model)
 {
     MenuSection menuSection;
     if (model.MenuSectionId == 0)
     {
         menuSection = new MenuSection
         {
             Name = model.Name,
             Number = model.Number,
         };
         _context.MenuSections.Add(menuSection);
     }
     else
     {
         menuSection = _context.MenuSections.FirstOrDefault(s => s.MenuSectionId == model.MenuSectionId);
         if (menuSection == null) return 0;
         menuSection.Name = model.Name;
         menuSection.Number = model.Number;
     }
     _context.SaveChanges();
     model.MenuSectionId = menuSection.MenuSectionId;
     RemoveExceedMenuItems(model);
     foreach (var menuItem in model.Items)
     {
         menuItem.MenuSectionId = model.MenuSectionId;
         menuItem.MenuId = model.MenuId;
         var id = UpdateMenuItem(menuItem);
         menuItem.MenuItemId = id;
     }
     return model.MenuSectionId;
 }
Esempio n. 2
0
 private void RemoveExceedMenuItems(MenuSectionViewModel model)
 {
     var vmIds = model.Items.Select(x => x.MenuItemId);
     var dbIds = _context.MenuItems.Where(x => x.MenuSectionId == model.MenuSectionId &&
                                               x.MenuId == model.MenuId)
         .Select(x => x.MenuItemId);
     var idsToBurn = dbIds.Where(x => !vmIds.Contains(x));
     _context.MenuItems.RemoveRange(_context.MenuItems.Where(x => idsToBurn.Contains(x.MenuItemId)));
 }
Esempio n. 3
0
        private static void ExtractMenu(List <DocLine> lines, ref List <MenuSectionViewModel> menu)
        {
            if (lines.Count == 0)
            {
                return;
            }
            if (menu == null)
            {
                menu = new List <MenuSectionViewModel>();
            }

            var section = lines.FirstOrDefault(l => !IsMenuItem(l));

            if (section == null)
            {
                return;
            }
            var nextSextion = lines.Where(l => l != section).FirstOrDefault(l => !IsMenuItem(l));
            var menuSection = new MenuSectionViewModel()
            {
                Name   = section.Text,
                Number = menu.Count + 1,
                Items  = new List <MenuItemViewModel>()
            };
            var items = lines.Where(l => l.Number > section.Number);

            if (nextSextion != null)
            {
                items = items.Where(l => l.Number < nextSextion.Number).ToList();
            }

            menuSection.Items.AddRange(items.Select(i => new MenuItemViewModel()
            {
                Name   = i.Text.RemoveNumber(),
                Number = menuSection.Items.Count() + 1
            }));
            lines.Remove(section);
            lines.RemoveRange(0, items.Count());
            menu.Add(menuSection);
            if (lines.Any())
            {
                ExtractMenu(lines, ref menu);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Creates the menu list.
        /// </summary>
        /// <param name="sectionPages">The section pages.</param>
        /// <returns>A list of KeyValuePairs contaning section page </returns>
        private List <KeyValuePair <MenuSectionViewModel, List <MenuContentViewModel> > > CreateMenuList(List <SectionPage> sectionPages)
        {
            var menuPages = new List <KeyValuePair <MenuSectionViewModel, List <MenuContentViewModel> > >();

            foreach (var page in sectionPages)
            {
                var sectionViewModel = new MenuSectionViewModel
                {
                    ID         = page.ContentLink.ID,
                    Title      = page.Name,
                    Icon       = page.Icon,
                    QuickLinks = page.MenuLinkList
                };

                var children = GetChildrenViewModels(page);

                menuPages.Add(new KeyValuePair <MenuSectionViewModel, List <MenuContentViewModel> >(sectionViewModel, children));
            }

            return(menuPages);
        }
        // GET: MenuSections/Create
        public ActionResult Create()
        {
            // Get the user Id
            userId = User.Identity.GetUserId();

            MenuSectionViewModel vm = new MenuSectionViewModel();
            // Get the menu of the resturant
            var resturant = db.Resturants.FirstOrDefault(r => r.UserId == userId);
            var menu      = db.Menus.FirstOrDefault(m => m.MenuId == resturant.ResturantId);

            // Get the Menu Types only not in the resturant menus
            List <MenuType>    menutypes    = db.MenuTypes.ToList();
            List <MenuSection> menuSections = db.MenuSections.Where(m => m.MenuId == menu.MenuId).ToList();

            var menuTypesNotInMenu = new List <MenuType>();

            foreach (var item in menuSections)
            {
                if (menutypes.Contains(item.MenuType))
                {
                    menutypes.Remove(item.MenuType);
                }
            }

            // Create the list of the select list
            List <SelectListItem> items = new List <SelectListItem>();

            foreach (var item in menutypes)
            {
                items.Add(new SelectListItem {
                    Text = item.Name, Value = item.MenuTypeId.ToString()
                });
            }

            vm.MenuTypes = new SelectList(items, "Value", "Text");

            vm.Resturant = resturant;

            return(View(vm));
        }
        public ActionResult Create([Bind(Include = "MenuTypeId")] MenuSectionViewModel menuSection)
        {
            // Get the user Id
            userId = User.Identity.GetUserId();

            // Get the resturant and menu
            var resturant = db.Resturants.FirstOrDefault(r => r.UserId == userId);

            if (ModelState.IsValid)
            {
                // Create a new object of type menu section
                MenuSection section = new MenuSection();
                section.MenuTypeId = menuSection.MenuTypeId;
                section.MenuId     = resturant.ResturantId;

                db.MenuSections.Add(section);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View(menuSection));
        }
        // GET: MenuSections
        public ActionResult Index()
        {
            // Get the user Id
            userId = User.Identity.GetUserId();

            MenuSectionViewModel vm = new MenuSectionViewModel();
            var resturant           = db.Resturants.FirstOrDefault(r => r.UserId == userId);

            vm.Resturant = resturant;
            vm.Message   = new MessageViewModel {
                Message = "This is the page of the menu types of the resturant " + resturant.Name, MessageType = MessageType.Info
            };
            // Get the menu of the resturant Id
            var menu = db.Menus.FirstOrDefault(m => m.Resturant.UserId == userId);

            if (menu != null)
            {
                vm.MenuSections = db.MenuSections.Where(m => m.MenuId == menu.MenuId).ToList();
            }

            return(View(vm));
        }
Esempio n. 8
0
        protected UpdateMenuViewModel GetFakeMenu(int menuId)
        {
            var sec   = TestContext.MenuSections.ToList();
            var model = new UpdateMenuViewModel
            {
                Editable  = true,
                Price     = 10000,
                MenuId    = menuId,
                Sections  = new List <MenuSectionViewModel>(),
                LunchDate = DateTime.Now.AddYears(1100).ToString(DateFormat)
            };

            foreach (var dbSection in sec)
            {
                var section = new MenuSectionViewModel()
                {
                    Number        = dbSection.Number,
                    Name          = dbSection.Name,
                    MenuSectionId = dbSection.MenuSectionId,
                    MenuId        = menuId,
                    Items         = new List <MenuItemViewModel>()
                };
                for (var i = 0; i < 100; i++)
                {
                    var item = new MenuItemViewModel()
                    {
                        MenuId        = menuId,
                        Number        = i,
                        Name          = Guid.NewGuid().ToString(),
                        MenuSectionId = section.MenuSectionId,
                    };

                    section.Items.Add(item);
                }
                model.Sections.Add(section);
            }
            return(model);
        }