Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            bool exists = false;

            foreach (var item in _context.Berths)
            {
                if (item.BerthId == Berth.BerthId)
                {
                    exists = true;
                }
            }

            if (exists)
            {
                ErrorMessage = "Pladsen findes allerede";
                return(Page());
            }
            else
            {
                _context.Berths.Add(Berth);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("Berths"));
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BoatExists(Boat.BoatId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

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