public ActionResult ChooseMentor(AddMentor mentor) { if (ModelState.IsValid) { if (string.IsNullOrEmpty(mentor.Email)) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var users = UserManager.FindByEmail(mentor.Email); if (users == null) { // Type options : info, danger, success, warning TempData["UserMessage"] = new JavaScriptSerializer().Serialize(new { Type = "danger", Title = "Error:", Message = "User not found" }); return(View()); } var userId = users.Id; var mentorUser = db.Users.Find(userId); var roles = UserManager.GetRoles(userId); if (roles.Contains("Mentor")) { ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId <int>()); Users currentUser = db.Users.Find(user.Id); if (currentUser.Id == users.Id) { // Type options : info, danger, success, warning TempData["UserMessage"] = new JavaScriptSerializer().Serialize(new { Type = "warning", Title = "Warning:", Message = "You cannot add yourself as a mentor!" }); return(View()); } currentUser.MentorId = users.Id; db.Entry(currentUser).State = EntityState.Modified; db.SaveChanges(); EmailController mail = new EmailController(); mail.MentorConfirmation(mentor.Email, currentUser.FirstName, currentUser.LastName, mentorUser.FirstName); // Type options : info, danger, success, warning TempData["UserMessage"] = new JavaScriptSerializer().Serialize(new { Type = "success", Title = "Success!", Message = "Mentor added correctly!" }); //return RedirectToAction("Mentee", "Options"); return(View()); } else { // Type options : info, danger, success, warning TempData["UserMessage"] = new JavaScriptSerializer().Serialize(new { Type = "warning", Title = "Warning:", Message = "User not registered as mentor" }); return(View()); } } return(View()); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); EmailController mail = new EmailController(); mail.SendConfirmation(model.Email); if (result.Succeeded) { var currentUser = UserManager.FindByName(user.UserName); if (model.RoleName == "Both") { var roleresult1 = UserManager.AddToRole(currentUser.Id, "Mentor"); var roleresult2 = UserManager.AddToRole(currentUser.Id, "Mentee"); } else { var roleresult = UserManager.AddToRole(currentUser.Id, model.RoleName); } await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Create", "Users")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Create([Bind(Include = "Id,Entry,UsersId,MentorId,SentimentScore,MentorFeedback,Date,MenteeFeedback")] DiaryEntries diaryEntries) { // Calculate the sentiment score of the text to save it in the database SentimentPy sent = new SentimentPy(); var score = sent.getSentimentScore(diaryEntries.Entry); diaryEntries.SentimentScore = score; // Get the user's information and update the diary before saving it ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId <int>()); Users currentUser = db.Users.Find(user.Id); diaryEntries.UsersId = currentUser.Id; diaryEntries.MentorId = currentUser.MentorId.Value; diaryEntries.Date = DateTime.Now; if (ModelState.IsValid) { // Save changes to DB db.DiaryEntries.Add(diaryEntries); db.SaveChanges(); // Send e-mail to mentor EmailController mail = new EmailController(); var UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var users = UserManager.FindById(diaryEntries.MentorId); Users mentor = db.Users.Find(users.Id); mail.NewDiary(users.Email, mentor.FirstName, currentUser.FirstName, currentUser.LastName); // Type options : info, danger, success, warning TempData["UserMessage"] = new JavaScriptSerializer().Serialize(new { Type = "success", Title = "Success!", Message = "Diary entry added correctly!" }); return(View()); } ViewBag.UsersId = new SelectList(db.Users, "Id", "FirstName", diaryEntries.UsersId); return(View(diaryEntries)); }
public ActionResult Edit([Bind(Include = "Id,TaskName,TaskDescription,MentorId,DueDate,CompletionDate,MentorFeedback,MenteeComments,MenteeRating,GoalsId")] Exercise exercise) { if (ModelState.IsValid) { db.Entry(exercise).State = EntityState.Modified; db.SaveChanges(); var goals = db.Goals.Find(exercise.GoalsId); var mentee = db.Users.Find(goals.UsersId); var UserManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var menteeUser = UserManager.FindById(mentee.Id); var mentorUser = UserManager.FindById(goals.MentorId); var ment = db.Users.Find(mentorUser.Id); EmailController mail = new EmailController(); mail.EditTask(menteeUser.Email, mentee.FirstName, ment.FirstName, ment.LastName); // Type options : info, danger, success, warning TempData["UserMessage"] = new JavaScriptSerializer().Serialize(new { Type = "success", Title = "Success!", Message = "Task updated correctly!" }); return(View(exercise)); } ViewBag.GoalsId = new SelectList(db.Goals, "Id", "GoalName", exercise.GoalsId); return(View(exercise)); }