Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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." }));
        }