/// <summary> /// Get a list of all the reservations /// </summary> /// <param name="room"></param> /// <returns></returns> public List <Reservation> GetReservations(Room room) { string query = "SELECT dbo.Reservation.id, dbo.Reservation.userId, dbo.Reservation.roomId, " + "dbo.Reservation.reservationName, dbo.Reservation.reservationStart, dbo.Reservation.reservationEnd " + "FROM dbo.Reservation WHERE dbo.Reservation.roomId = @roomId"; SqlCommand command = new SqlCommand(query, new SqlConnection(connnectionstring)); command.Parameters.AddWithValue("@roomId", room.Id); using (command) { List <Reservation> reservations = new List <Reservation>(); command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { User tempUser = new UserSQLContext().GetUser((int)reader["userId"]); reservations.Add(new Reservation((int)reader["id"], tempUser, room, (string)reader["reservationName"], (DateTime)reader["reservationStart"], (DateTime)reader["reservationEnd"])); } } command.Connection.Close(); return(reservations); } }
public bool CheckForRight(int rightid) { UserSQLContext context = new UserSQLContext(); UserRepository userrepository = new UserRepository(context); int id = Convert.ToInt32(HttpContext.Session.GetInt32("id")); User user = userrepository.GetUser(id); return(user.Role.Rights.Any(f => f.Id == rightid)); }
public IActionResult Create(UserViewModel viewModel) { base.CheckForLogin(); if (ModelState.IsValid) { UserSQLContext context = new UserSQLContext(); UserRepository repository = new UserRepository(context); repository.Register(viewModel.Email, viewModel.Password, viewModel.Firstname, viewModel.Lastname, viewModel.Telnr, viewModel.Infix); ConfirmAccount(viewModel); } return(View()); }
public IActionResult Login(LoginViewModel viewModel) { UserSQLContext context = new UserSQLContext(); UserRepository repoUser = new UserRepository(context); if (ModelState.IsValid) { User user = repoUser.Login(viewModel.Email, viewModel.Password); if (user != null) { HttpContext.Session.SetInt32("id", user.Id); return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("ErrorMessage", "Invald login credentials"); } return(View("Login")); }