//log out
        // POST: Visitors/LogOut/5
        public async Task <IActionResult> LogOut(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Visitor visitor = await _context.Visitor.FindAsync(id);

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

            if (ModelState.IsValid)
            {
                visitor.DateOut = DateTime.Now;
                _context.Update(visitor);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(NotFound());
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FirstName,LastName,Business,DateIn,DateOut")] Visitors visitors)
        {
            if (id != visitors.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(visitors);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!VisitorsExists(visitors.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(visitors));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Department,VisitorCount")] StaffNames staffNames)
        {
            if (id != staffNames.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(staffNames);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StaffNamesExists(staffNames.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(staffNames));
        }
Beispiel #4
0
        public void IncrementStaffCount(int id)
        {
            var MostRecentStaffVisited = (StaffNames)_context.StaffNames.Find(id);

            //_context.Visitor.OrderByDescending(u => u.Id).FirstOrDefault();
            //Debug.Assert(MostRecentVisitor != null, nameof(MostRecentVisitor) + " != null");
            MostRecentStaffVisited.VisitorCount++;
            _context.Update(MostRecentStaffVisited);
            _context.SaveChangesAsync();
            //
            //
            //
            // _context.StaffNames.OrderByDescending(u => u.Id).FirstOrDefault();
            //  staffNames.VisitorCount++;
        }
        public void VisitorLogout(int?id)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //get back the visitor that is being logged out
                    var updateVisitor = _context.Visitors
                                        .FirstOrDefaultAsync(m => m.Id == id);
                    //update with logout time
                    updateVisitor.Result.DateOut = DateTime.Now;

                    _context.Update(updateVisitor);
                    _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    Console.WriteLine("Visitor Logout not saved");
                }
            }
        }