public ActionResult Index(string username) { try { if (username == User.Identity.Name) { throw new Exception("You can't send message to yourself :D"); } Databases.Neo4j.DomainModel.User userProfile = neo4j.GetUser(username); ViewBag.reciever = username; var messages = neo4j.GetAllMessagesBetweenUsers(User.Identity.Name, username); ViewBag.loggedPicture = neo4j.GetUserProfilePicture(User.Identity.Name).url.Replace('~', ' '); redis.RemoveUnreadMessages(User.Identity.Name, username); if (userProfile != null) { return(View(neo4j.GetAllMessagesBetweenUsers(User.Identity.Name, username))); } else { throw new Exception("There is no user with that username :("); } } catch (Exception ex) { return(View("CustomError", ex)); } }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // Creating user node in neo4j db saving only his aspid and username Neo4jFunctions neo4j = new Neo4jFunctions(); Databases.Neo4j.DomainModel.User newUser = new Databases.Neo4j.DomainModel.User { aspid = user.Id, username = model.UserName }; neo4j.CreatePictureRelationship(new Databases.Neo4j.DomainModel.Relationships.HasProfilePicture { user = newUser, profilePicture = new Databases.Neo4j.DomainModel.Picture { url = newUser.profilepictureurl }, time = DateTime.Now.ToString() }, null); RedisFunctions redis = new RedisFunctions(); redis.PushUsernameToSearchList(model.UserName); // 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("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }