// 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()
        {
            SameFound = _context.Languages
                        .Any(l => l.LanguageId != Language.LanguageId &&
                             (l.LanguageName.ToLower()) == (Language.LanguageName.ToLower()));


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

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LanguageExists(Language.LanguageId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemple #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()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PublisherExists(Publisher.PublisherId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemple #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()
        {
            SameFound = _context.Authors
                        .Any(a => a.AuthorId != Author.AuthorId &&
                             ((a.FirstName.ToLower()) == (Author.FirstName.ToLower()) &&
                              a.LastName.ToLower() == (Author.LastName.ToLower())));

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

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AuthorExists(Author.AuthorId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
Exemple #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.Attach(BookAuthor).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookAuthorExists(BookAuthor !.BookAuthorId))
                {
                    return(NotFound());
                }
Exemple #5
0
        public async Task <ActionResult> OnGetAsync(int?foodItemId, int?personId, int?removeItemId, string?search, string?toDoActionReset)
        {
            if (toDoActionReset == "Reset")
            {
                Search = "";
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(search))
                {
                    Search = search.Trim();
                }
            }
            var itemsQuery = _context.FoodItems.Include(o => o.Category).AsQueryable();

            if (!string.IsNullOrWhiteSpace(Search))
            {
                if (Search.Contains("%21"))
                {
                    itemsQuery = itemsQuery.Where(b =>
                                                  !b.FoodItemName.Contains(Search) ||
                                                  !b.Category.CategoryName.Contains(Search));
                }
                else
                {
                    itemsQuery = itemsQuery.Where(b =>
                                                  b.FoodItemName.Contains(Search) ||
                                                  b.Category.CategoryName.Contains(Search));
                }
            }

            SavedPersonId = personId.Value;
            if (removeItemId.HasValue)
            {
                var dOrderItems = _context.OrderItems.First(n => n.OrderItemId == removeItemId && n.PersonId == personId);
                _context.Attach(dOrderItems);
                _context.Remove(dOrderItems);
                _context.SaveChanges();
            }
            if (!foodItemId.Equals(null) && personId.HasValue)
            {
                var newFoodItem  = _context.FoodItems.First(n => n.FoodItemId == foodItemId);
                var newOrderItem = new OrderItem()
                {
                    PersonId   = personId.Value,
                    FoodItem   = newFoodItem,
                    FoodItemId = newFoodItem.FoodItemId,
                    Sum        = newFoodItem.Price
                };
                _context.OrderItems.Add(newOrderItem);
                await _context.SaveChangesAsync();
            }

            itemsQuery = itemsQuery.OrderBy((b => b.Category.CategoryId));
            Items      = await itemsQuery.ToListAsync();

            //var orderedItem = _context.OrderItems.First(n => n.OrderItemId == orderItemId);
            //var personId = orderedItem.PersonId;

            var orderedItemsQuery =
                _context.OrderItems
                .Where(n => n.PersonId == personId)
                .AsQueryable()
                .Include(o => o.FoodItem)
                .Include(o => o.FoodItem.Category);

            OrderedItems = await orderedItemsQuery.ToListAsync();

            return(Page());
        }