Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostSaveMeal(int?id)
        {
            if (id == null)
            {
                throw new Exception("Bad call of this method.");
            }
            Menu = await _context.Menus.AsNoTracking().FirstOrDefaultAsync(m => m.ID == id);

            var emptyMeal = new Meal
            {
                MenuID = Menu.ID
            };

            if (await TryUpdateModelAsync <Meal>(
                    emptyMeal,
                    "meal",
                    m => m.Day, m => m.MealType))
            {
                _context.Meals.Add(MealToCreate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("#"));
            }

            return(await OnGetAsync(id));
        }
Ejemplo n.º 2
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var menuToUpdate = await _context.Menus.FindAsync(id);

            if (menuToUpdate == null)
            {
                return(NotFound());
            }

            if (await TryUpdateModelAsync(
                    menuToUpdate,
                    "menu", // Prefix for form value.
                    m => m.MenuName, m => m.CampID, m => m.StartDate, m => m.EndDate))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }

            // Select CampID if TryUpdateModelAsync fails.
            PopulateCampsDropDownList(_context, Menu.CampID);
            return(Page());
        }
Ejemplo n.º 3
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Ingredient).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!IngredientExists(Ingredient.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Ejemplo n.º 4
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Camps.Add(Camp);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }