// To protect from overposting attacks, 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(FoodKind).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FoodKindExists(FoodKind.FoodKindID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, 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.MealKind.Add(MealKind);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Esempio n. 3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MealKind = await _context.MealKind.FindAsync(id);

            if (MealKind != null)
            {
                _context.MealKind.Remove(MealKind);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Pantry = await _context.Pantry.FindAsync(id);

            if (Pantry != null)
            {
                _context.Pantry.Remove(Pantry);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Esempio n. 5
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            try
            {
                var menus = _context.Menu
                            .AsEnumerable()
                            .Where(b => b.MealDate.ToShortDateString() == Menu.MealDate.ToShortDateString() && Menu.MealKindID == b.MealKindID)
                            .ToList();

                if (menus != null)
                {
                    if (menus.Count() > 0)
                    {
                        return(RedirectToPage("./Index"));
                    }
                }
            }
            catch (Exception ex)
            {
                string s = ex.Message;
                return(RedirectToPage("./Index"));
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            switch (Menu.MealKindID)
            {
            case 1:
                Menu.MealDate.AddHours(12);
                break;

            case 2:
                Menu.MealDate.AddHours(18);
                break;
            }
            _context.Menu.Add(Menu);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Esempio n. 6
0
        // To protect from overposting attacks, 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());
            }
            // check for existing record for that food
            var pantrys = _context.Pantry
                          .AsEnumerable()
                          .Where(b => b.FoodID == Pantry.FoodID)
                          .ToList();

            if (pantrys.Count > 0)
            {
                return(RedirectToPage("./Index"));
            }

            _context.Pantry.Add(Pantry);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
Esempio n. 7
0
        // To protect from overposting attacks, 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());
            }

            // NO DUPLICATES
            var foods = _context.Food
                        .AsEnumerable()
                        .Where(b => b.Name == Food.Name)
                        .ToList();

            if (foods.Count > 0)
            {
                return(RedirectToPage("./Index"));
            }

            // Add New Food
            _context.Food.Add(Food);
            await _context.SaveChangesAsync();

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