public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser()
                {
                    UserName = model.UserName
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInAsync(user, isPersistent : false);

                    // Audit registration
                    Audit audit = new Audit();
                    audit.Date   = DateTime.Now;
                    audit.UserId = user.Id;
                    audit.Event  = "User registration: " + user.UserName;
                    var audit_result = new AuditsController().Create(audit);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindAsync(model.UserName, model.Password);

                if (user != null)
                {
                    await SignInAsync(user, model.RememberMe);

                    // Audit login
                    Audit audit = new Audit();
                    audit.Date   = DateTime.Now;
                    audit.UserId = user.Id;
                    audit.Event  = "User login: "******"", "Invalid username or password.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult LogOff()
        {
            // Audit registration
            Audit audit = new Audit();

            audit.Date   = DateTime.Now;
            audit.UserId = User.Identity.GetUserId();
            audit.Event  = "User logoff: " + User.Identity.GetUserName();
            var audit_result = new AuditsController().Create(audit);

            AuthenticationManager.SignOut();
            return(RedirectToAction("Index", "Home"));
        }
Пример #4
0
        // GET: Bookings/Create
        public ActionResult Create()
        {
            //db.Database.ExecuteSqlCommand("DELETE FROM Bookings");
            int.TryParse(Request.QueryString["RoomNumber"], out selectedRoomNumber);
            if (selectedRoomNumber == 0)
            {
                selectedRoomNumber = 1;
            }

            // create list of room numbers for dropdown
            List <SelectListItem> roomNums = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = "1", Value = "1"
                },
                new SelectListItem()
                {
                    Text = "2", Value = "2"
                },
                new SelectListItem()
                {
                    Text = "3", Value = "3"
                },
                new SelectListItem()
                {
                    Text = "4", Value = "4"
                },
                new SelectListItem()
                {
                    Text = "5", Value = "5"
                }
            };

            ViewBag.RoomNumbersList = new SelectList(roomNums, "Value", "Text", selectedRoomNumber);

            SetCalendar();

            // Audit bookings view
            Audit audit = new Audit();

            audit.Date   = DateTime.Now;
            audit.UserId = User.Identity.GetUserId();
            audit.Event  = "User view bookings: " + User.Identity.GetUserName() + " (Room:" + selectedRoomNumber + ")";
            var audit_result = new AuditsController().Create(audit);

            return(View());
        }
Пример #5
0
        public ActionResult Create([Bind(Include = "ID,RoomNumber,FromDate,ToDate,userId")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                booking.userId = User.Identity.GetUserId();
                db.Bookings.Add(booking);
                db.SaveChanges();

                // Audit booking submitted
                Audit audit = new Audit();
                audit.Date   = DateTime.Now;
                audit.UserId = User.Identity.GetUserId();
                audit.Event  = "User booking submitted: " + User.Identity.GetUserName() + " (Room:" + booking.RoomNumber + ")";
                var audit_result = new AuditsController().Create(audit);

                return(RedirectToAction("Details/" + booking.ID));
            }

            return(View(booking));
        }
        // GET: /Feedback/
        public ActionResult Index(string client, string comment)
        {
            // define LINQ query for search
            var results = from m in db.Feedback
                          select m;

            bool search = false;

            // filter by Client if client search string has been specified
            if (!String.IsNullOrEmpty(client))
            {
                results = results.Where(s => s.ClientName.Contains(client));
                search  = true;
            }

            // filter by Comments if comment search string has been specified
            if (!String.IsNullOrEmpty(comment))
            {
                results = results.Where(s => s.Comment.Contains(comment));
                search  = true;
            }

            // Audit (only if a user is logged-in)
            if (User.Identity.GetUserId() != null && User.Identity.GetUserId() != String.Empty)
            {
                Audit audit = new Audit();
                audit.Date   = DateTime.Now;
                audit.UserId = User.Identity.GetUserId();
                audit.Event  = "User search: " + User.Identity.GetUserName() +
                               " (ClientSearchVal: " + client + ")" +
                               " (CommentSearchVal: " + comment + ")";
                var audit_result = new AuditsController().Create(audit);
            }

            if (search)
            {
                return(View(results));
            }

            return(View(db.Feedback.ToList()));
        }