public async Task SetValues(ApplicationDbContext db, int ID) { Visitor v = await db.Visitors.SingleOrDefaultAsync(x => x.ID == ID); JackLib.CopyValues(v, this); this.Event = (await db.Events.SingleOrDefaultAsync(x => x.ID == v.EID)).Name; Types = await VType.GenerateTypes(db, v.EID); Tickets = await Ticket.GenerateTypes(db, v.EID); }
public async Task <IActionResult> Delete(int?ID) { if (ID == null) { return(RedirectToAction("Events", "Owner")); } Ticket ticket = await _db.Tickets.FirstOrDefaultAsync(x => x.ID == ID); JackLib.IfNull(ticket); return(View(ticket)); }
public async Task <IActionResult> Copy(int?ID) { if (ID == null) { return(RedirectToAction("Events", "Owner")); } Ticket ticket = await _db.Tickets.SingleOrDefaultAsync(x => x.ID == ID); JackLib.IfNull(ticket); // get current event's name ViewBag.Event = (await _db.Events.SingleOrDefaultAsync(x => x.ID == ticket.EID)).Name; return(View(ticket)); }
public void AddLog(string stage, string description, bool change = false) { VisitorLog vl = new VisitorLog(); if (change) // if chnages need to be saved { vl.CurrentState = new Change(); JackLib.CopyValues(this, vl.CurrentState); } vl.Type = stage; vl.Action = description; vl.VID = this.ID; vl.Date = DateTime.Now.ToString("yyyy-MM-dd"); vl.Time = DateTime.Now.ToString("HH:mm"); this.Logs.Add(vl); }
public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { // create a new user ApplicationUser owner = new ApplicationUser { UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, Level = model.Level }; var result = await _userManager.CreateAsync(owner, model.Password); // LogIn if (result.Succeeded) { ApplicationUser registeredOwner = await _userManager.FindByEmailAsync(model.Email); // Adding All Claims List <PropertyInfo> properties = JackLib.PropertyAsObject(new Claims()); foreach (var item in properties) { await _userManager.AddClaimAsync(registeredOwner, new Claim(item.Name, "")); } // log for the owner await _db.Logs.AddAsync(await Log.New("Register", $"Owner's initial registration", _id, _db)); // sign in after adding claims await _signInManager.SignInAsync(registeredOwner, isPersistent : false); return(RedirectToAction("Index", "Owner")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
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." })); }