public ActionResult DeletePost(int id) { UserDetailsContext context = new UserDetailsContext(); var post = context.Posts.SingleOrDefault(x => x.PostId == id); var postC = context.Comments.Where(x => x.PostId == id).ToList();; context.Comments.RemoveRange(postC); context.SaveChanges(); context.Posts.Remove(post); context.SaveChanges(); return(RedirectToAction("ProfilePage", "Home")); }
public ActionResult Dislike(int id) { UserDetailsContext context = new UserDetailsContext(); var userId = Convert.ToInt32(Session["UserId"]); var post = context.LikesDetails.SingleOrDefault(x => x.PostId == id && x.UserId == userId); context.LikesDetails.Remove(post); context.SaveChanges(); var like = context.Posts.Find(id); like.Like -= 1; context.SaveChanges(); return(RedirectToAction("Main", "Home")); }
public ActionResult Register(RegisterViewModel registerViewModel) { ScryptEncoder encode = new ScryptEncoder(); UserDetailsContext context = new UserDetailsContext(); if (!ModelState.IsValid) { return(View("SignUp", registerViewModel)); } var userExistence = context.UserDetails.SingleOrDefault(x => x.Email == registerViewModel.UserDetails.Email); if (userExistence != null) { ViewBag.UserAlreadyExists = "User Already Exists"; return(View("SignUp", registerViewModel)); } if (registerViewModel.ConfirmPassword != registerViewModel.UserDetails.Password) { ViewBag.UserAlreadyExists = "Password And Confirm Password Mismatch"; return(View("SignUp", registerViewModel)); } registerViewModel.UserDetails.Password = encode.Encode(registerViewModel.UserDetails.Password); registerViewModel.UserDetails.UserName = "******"; context.UserDetails.Add(registerViewModel.UserDetails); context.SaveChanges(); // @ViewBag.success = "Account Created Succesfully Login to continue"; this.AddNotification("Account Created Succesfully Login to continue", NotificationType.SUCCESS); return(View("SignUp")); }
public ActionResult Like(int id) { UserDetailsContext context = new UserDetailsContext(); var userId = Convert.ToInt32(Session["UserId"]); LikesDetails likesDetails = new LikesDetails { PostId = id, UserId = userId }; context.LikesDetails.Add(likesDetails); context.SaveChanges(); var count = context.LikesDetails.Where(x => x.PostId == id).Count(); var post = context.Posts.Find(id); post.Like = count; context.SaveChanges(); return(RedirectToAction("Main", "Home")); }
public ActionResult SaveEdit(UserProfileDetails userProfileDetails) { UserDetailsContext context = new UserDetailsContext(); UserDetailsContext contextt = new UserDetailsContext(); UserDetailsContext contexttt = new UserDetailsContext(); UserDetails userDetails = new UserDetails(); if (!ModelState.IsValid) { return(View("Edit", userProfileDetails)); } var userId = Convert.ToInt32(Session["UserId"]); var userExistence = context.UserProfileDetails.SingleOrDefault(x => x.UserId == userId); var userExistenceInMain = contextt.UserDetails.SingleOrDefault(x => x.Id == userId); if (contexttt.UserProfileDetails.Any(x => x.UserName == userProfileDetails.UserName && x.UserId != userId)) { ViewBag.error = "UserName already Exists . Try With other name"; return(View("Edit")); } if (userExistence == null) { userProfileDetails.UserId = userId; context.UserProfileDetails.Add(userProfileDetails); context.SaveChanges(); userExistenceInMain.UserName = userProfileDetails.UserName; contextt.SaveChanges(); return(RedirectToAction("ProfilePage", "Home")); } userExistence.UserName = userProfileDetails.UserName; userExistence.Bio = userProfileDetails.Bio; context.SaveChanges(); userExistenceInMain.UserName = userProfileDetails.UserName; contextt.SaveChanges(); return(RedirectToAction("ProfilePage", "Home")); }
public Task HandleAsync(AddUserDetails command) { var userDetails = new Models.UserDetails { CreationDate = DateTime.Now, EmailAddress = command.EmailAddress, Name = command.Name, Surname = command.Surname, Id = 3 }; _context.UserDetails.Add(userDetails); _context.SaveChanges(); return(Task.CompletedTask); }
public ActionResult AddComment(ProfilepageViewModel profilepageViewModel, string buttonvalue) { var userId = Session["UserId"]; var postId = buttonvalue; UserDetailsContext context = new UserDetailsContext(); Comments comments = new Comments { PostId = Convert.ToInt32(postId), UserId = Convert.ToInt32(userId), Comment = profilepageViewModel.UserComment }; context.Comments.Add(comments); context.SaveChanges(); return(RedirectToAction("Main", "Home")); }
public ActionResult SavePost(Posts posts) { UserDetailsContext context = new UserDetailsContext(); posts.UserId = Convert.ToInt32(Session["UserId"]); if (!ModelState.IsValid) { return(View("AddPost", posts)); } posts.UserName = Session["UserName"].ToString(); posts.PostDateTime = DateTime.Now; context.Posts.Add(posts); context.SaveChanges(); this.AddNotification("Post Successfully Uploaded", NotificationType.SUCCESS); return(RedirectToAction("Main", "Home")); }