public IActionResult Login([Bind("Email,Password")] User user)
        {
            var loggedUser = db
                             .Users
                             .Where(u => u.Email == user.Email && u.Password == user.Password)
                             .Include(u => u.Events)
                             .FirstOrDefault();

            if (loggedUser == null)
            {
                return(View(user));
            }

            loggedUser.IsLogged = true;

            db
            .Users
            .Where(u => u.Id == loggedUser.Id)
            .FirstOrDefault()
            .IsLogged = true;

            db.SaveChanges();

            return(RedirectToAction($"Manager/{loggedUser.Id}", "Account"));
        }
Exemple #2
0
        // Delete an event
        public IActionResult Delete(int?id)
        {
            var eventToRemove = db
                                .Events
                                .Where(e => e.Id == id)
                                .FirstOrDefault();

            var user = db
                       .Users
                       .Where(u => u.Events.Any(e => e.Id == id))
                       .FirstOrDefault();

            db
            .Events
            .Remove(eventToRemove);

            db.SaveChanges();

            return(RedirectToAction($"Manager/{user.Id}"));
        }