示例#1
0
		// RemoveMenuItem(item) => void
		// Removes an item (MenuItems)
		// PRODUCTION: comment out for production code. This will not be available.
		public Task RemoveMenuItem(MenuItems item)
		{
			if (item != null)
			{
				if (database.Entry(item).State == EntityState.Detached)
				{
					database.Menu.Attach(item);
				}
				database.Menu.Remove(item);
			}
			return database.SaveChangesAsync();
		}
示例#2
0
		// AddMenuItemAsync(item) => void
		// Takes an item (MenuItems) and adds it to the Menu table in the database
		// PRODUCTION: comment out for production code. This will not be available.
		public async Task AddMenuItemAsync(MenuItems item)
		{
			try {
				this.database.Menu.Add(item);
				await database.SaveChangesAsync();
				return;
			} catch (DbEntityValidationException ex)
			{
				var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);
				var fullErrorMessage = string.Join("; ", errorMessages);
				var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);
				throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
			}
		}
示例#3
0
		public async Task<ActionResult> MenuAdmin(MenuAdministrationView model)
		{
			setDisplayParams();
			// checks just in case the model fails.
			if (ModelState.IsValid)
			{
				// create the menu item first
				MenuItems item = new MenuItems() { HasSpicy = model.HasSpice == HasSpice.Yes ? true : false, HalfOrderPrice = model.HalfOrderPrice, Description = model.ItemDesc, Name = model.ItemName, Price = model.BasePrice, Category = model.Category, ImgURL = model.Url, Created = DateTime.Now };
				// are we dealing with options or just a menu item
				if (model.Options != null)
				{
					item.HasOptions = true;
					foreach (var option in model.Options)
					{
						option.MenuItemId = item.Id;
						await new OrderHandler().AddMenuOptionAsync(option);
					}
				}
				await new OrderHandler().AddMenuItemAsync(item);
				return RedirectToAction("MenuAdmin");
			}
			return View();
		}