public IActionResult RefineSearchAction(int RoomID) { int loggedUser = -1; if (HttpContext.Session.GetInt32("Userid") != null) { loggedUser = (int)HttpContext.Session.GetInt32("Userid"); } else { return(RedirectToAction("Login", "Users", null)); } if (_context.UserRooms.Where(usr => usr.UserID == loggedUser && usr.RoomID == RoomID).Count() > 0) { return(RedirectToAction("EnterRoom", new { id = RoomID })); } Notification newRequest = new Notification { Type = "Request", Date = DateTime.Now, RoomID = RoomID, RoomName = _context.Rooms.Find(RoomID).Nome, UserName = _context.Users.Find(loggedUser).Username, UserID = loggedUser }; _context.Add(newRequest); int mentor = _context.UserRooms.Where(usr => usr.RoomID == RoomID && usr.UserTypeID == 1).FirstOrDefault().UserID; NotificationUser nu = new NotificationUser { UserID = mentor, Notification = newRequest, Visible = 1 }; _context.Add(nu); _context.SaveChanges(); return(RedirectToAction("DashBoard", "Users")); }
public async Task <IActionResult> Create([Bind("UserID,Email,Username,Password")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public IActionResult CreateAnswer(String Content) { // get room int room_id = (int)HttpContext.Session.GetInt32("RoomID"); // get logged user int loggedUser = (int)HttpContext.Session.GetInt32("Userid"); //get QuestionID int questionID = (int)HttpContext.Session.GetInt32("QuestionID"); // Create new answer and save it on db Answer a; // If it's a mentor answering automatically mark as valid int usertype = _context.UserRooms.Where(ur => ur.RoomID == room_id && ur.UserID == loggedUser).FirstOrDefault().UserTypeID; if (_context.UserTypes.Find(usertype).Description == "Mentor" || _context.UserTypes.Find(usertype).Description == "Admin") { a = new Answer { Content = Content, Date = DateTime.Now, QuestionID = questionID, UserID = loggedUser, Valid = true, UserName = _context.Users.Find(loggedUser).Username }; } else { a = new Answer { Content = Content, Date = DateTime.Now, QuestionID = questionID, UserID = loggedUser, Valid = false, UserName = _context.Users.Find(loggedUser).Username } }; _context.Answers.Add(a); // Notify owner of the question and followers Question q = _context.Questions.Find(questionID); Notification n = new Notification { Type = "New answer on question " + q.Title, Date = DateTime.Now, RoomID = room_id, RoomName = _context.Rooms.Find(room_id).Nome, UserName = _context.Users.Find(loggedUser).Username, UserID = loggedUser }; _context.Add(n); // Owner NotificationUser owner = new NotificationUser { UserID = q.UserID, Notification = n, Visible = 1 }; if (owner.UserID != loggedUser) { _context.Add(owner); } // Followers foreach (FollowerQuestion fq in _context.FollowerQuestions.Where(fq => fq.FollowingID == q.QuestionID)) { NotificationUser nu = new NotificationUser { UserID = fq.FollowerID, Notification = n }; if (nu.UserID != loggedUser && nu.UserID != owner.UserID) { _context.Add(nu); } } _context.SaveChanges(); return(RedirectToAction("EnterQuestion", new { id = questionID })); }