示例#1
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(Visitation visitation)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var VisitationSelected = _context.Visitations
                                     .Include(v => v.Person).First(x => x.Id == visitation.Id);

            VisitationSelected.CheckOutDateTime = DateTime.Now;


            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VisitationExists(Visitation.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("/Welcome/Welcome"));
        }
示例#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()
        {
            ViewData["VisitTypes"] = new SelectList(_context.VisitTypes, "Id", "Type");
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Person person = _context.Persons.FirstOrDefault(x => x.FirstName == Visitation.Person.FirstName && x.LastName == Visitation.Person.LastName);

            if (person == null)
            {
                _context.Persons.Add(new Person {
                    FirstName = Visitation.Person.FirstName, LastName = Visitation.Person.LastName, Company = Visitation.Person.Company, LicencePlate = Visitation.Person.LicencePlate
                });
                await _context.SaveChangesAsync();

                person = _context.Persons.FirstOrDefault(x => x.FirstName == Visitation.Person.FirstName && x.LastName == Visitation.Person.LastName);
            }


            var newVisitation = new Visitation
            {
                CheckInDateTime  = DateTime.Now,
                CheckOutDateTime = DateTime.Now.AddHours(4),
                Person           = person,
                PersonId         = person.Id,
                VisitTypeId      = Visitation.VisitType.Id
            };



            // persist to get newOrder.Id

            _context.Visitations.Add(newVisitation);

            await _context.SaveChangesAsync();

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