public async Task <IActionResult> RegisterOk(Visitor model) { if (!ModelState.IsValid) { return(RedirectToAction("Menu", "Home", new { EID = model.EID })); } // if dublicate found/already registered if (await _db.Visitors.AnyAsync(x => x.OrderNumber == model.OrderNumber && x.Name == model.Name && x.Last == model.Last)) { ViewBag.Message = "Record for this attendee already exist. If you have any questions please refer to one of the representative."; return(View("Register", model)); } await model.CompleteRegistration(_db); Event e = await _db.Events.FirstOrDefaultAsync(x => x.ID == model.EID); // add log for visitor model.AddLog("Registration", "Initial", true); e.Visitors.Add(model); await Order.Increment(model.OrderNumber, _db); await _db.SaveChangesAsync(); return(View(model)); }
public async Task <IActionResult> CheckIn(Visitor model) { if (model.RegistrationNumber == null || model.EID == 0) { return(RedirectToAction("Menu", "Home", new { EID = model.EID })); } Visitor newVisitor = await _db.Visitors.SingleOrDefaultAsync(x => x.RegistrationNumber == model.RegistrationNumber); if (newVisitor != null) { if (newVisitor.CheckIned) { ViewBag.Message = "This Registration number was already used for Check In and name tag was printed. If you would like to change some information displayed on the name tag, please refer to the administrator."; ViewBag.EID = model.EID; return(View("PreCheckIn", model)); } ViewBag.Event = (await _db.Events.SingleOrDefaultAsync(x => x.ID == model.EID)).Name; // add lof for visitor newVisitor.AddLog("Check In", "Check-In Started", true); await _db.SaveChangesAsync(); return(View(newVisitor)); } ViewBag.Message = "This Registration number isn't correct. Please try again."; return(View("PreCheckIn", model)); }
public async Task <IActionResult> DeleteOk(int?ID) { if (ID == null) { return(RedirectToAction("Dashboard", "Admin", new { message = "Couldn't execute this request." })); } // update and save visitor Visitor visitor = await _db.Visitors.SingleOrDefaultAsync(x => x.ID == ID); visitor.Deleted = true; // change the number of checked-in tickets for this order number await Order.Decrement(visitor.OrderNumber, _db); // get admin ApplicationUser user = await _userManager.GetUserAsync(User); // visitor log visitor.AddLog("ADMIN", $"DELETED BY {user.Level}: {user.FirstName} {user.LastName}"); _db.Visitors.Update(visitor); // admin log await _db.Logs.AddAsync(await Log.New("Visitor", $"Visitor(ID: {visitor.ID}) {visitor.Name} {visitor.Last} was DELETED.", user.Id, _db)); return(RedirectToAction("ViewVisitor", "Admin", new { ID = visitor.ID })); }
public async Task <IActionResult> EditOk(Visitor model) { if (!ModelState.IsValid) { return(RedirectToAction("Menu", "Home", new { EID = model.EID })); } Visitor oldVisitor = await model.CopyValues(_db); // add log for visitor oldVisitor.AddLog("Check In", "Edition Completed", true); _db.Visitors.Update(oldVisitor); await _db.SaveChangesAsync(); return(View(oldVisitor)); }
public async Task <IActionResult> Edit(string number) { Visitor visitor = await _db.Visitors.FirstOrDefaultAsync(x => x.RegistrationNumber == number); if (number == null || visitor == null || visitor.CheckIned) { return(RedirectToAction("Welcome", "Home")); } // add log for visitor visitor.AddLog("Check In", "Edition Started", true); _db.Visitors.Update(visitor); await _db.SaveChangesAsync(); return(View(visitor)); }
public async Task <IActionResult> Reinstate(int?ID) { if (ID == null) { return(RedirectToAction("Dashboard", "Admin", new { message = "Couldn't execute this request." })); } // update visitor's status Visitor visitor = await _db.Visitors.SingleOrDefaultAsync(x => x.ID == ID); visitor.Deleted = false; // check if all tickets for this order were used Order order = await _db.Orders.SingleOrDefaultAsync(x => x.Number.ToString() == visitor.OrderNumber); if (order.Full) { // log for admin await _db.Logs.AddAsync(await Log.New("Visitor", $"Attempt to REINSTATE Visitor(ID: {visitor.ID}) {visitor.Name} {visitor.Last} failed. Order is FULL", _id, _db)); return(RedirectToAction("Dashboard", "Admin", new { message = "This Visitor can NOT be reinstated. All tickets were used. Advise the visitor to purchase another ticket or ask Manager for assistance." })); } // admin ApplicationUser user = await _userManager.GetUserAsync(User); // log for visitor visitor.AddLog("ADMIN", $"REINSTATED BY {user.Level}: {user.FirstName} {user.LastName}"); _db.Visitors.Update(visitor); // change the number of checked-in tickets for this order number await Order.Increment(visitor.OrderNumber, _db); // log for admin await _db.Logs.AddAsync(await Log.New("Visitor", $"Visitor(ID: {visitor.ID}) {visitor.Name} {visitor.Last} was REINSTATED.", _id, _db)); return(RedirectToAction("ViewVisitor", "Admin", new { ID = visitor.ID })); }
public async Task <IActionResult> CheckInOk(string number, int?EID) { if (number == null || EID == null) { return(RedirectToAction("Welcome", "Home")); } Visitor visitor = await _db.Visitors.SingleOrDefaultAsync(x => x.RegistrationNumber == number); if (visitor == null || visitor.CheckIned) { ViewBag.Message = "Something went wrong. Please try again."; return(RedirectToAction("Menu", "Home", new { EID = EID })); } visitor.CompleteCheckIn(); // add log for visitor visitor.AddLog("Check In", "Check-In Completed. Tag Printed", true); _db.Visitors.Update(visitor); await _db.SaveChangesAsync(); return(View()); }
public async Task <IActionResult> EditVisitor(EditVisitor model) { if (ModelState.IsValid) { // get visitor by id Visitor visitor = await _db.Visitors.SingleOrDefaultAsync(x => x.ID == model.ID); ApplicationUser user = await _userManager.GetUserAsync(User); // logs for visitor string action; if (!visitor.Blocked && model.Blocked) { action = "BLOCKED"; } else if (visitor.Blocked && !model.Blocked) { action = "UNBLOCKED"; } else { action = "CHANGED"; } visitor.AddLog("ADMIN", $"{action} BY {user.Level}: {user.FirstName} {user.LastName}", true); // update and save visitor JackLib.CopyValues(model, visitor); _db.Visitors.Update(visitor); // log for admin await _db.Logs.AddAsync(await Log.New("Visitor", $"Visitor witg ID: {visitor.ID}, was EDITED", _id, _db)); return(RedirectToAction("ViewVisitor", "Admin", new { ID = model.ID })); } return(RedirectToAction("Dashboard", "Admin", new { message = "Couldn't execute this request. Please try again." })); }