public ActionResult Update(string message) { if (!string.IsNullOrEmpty(message)) { var context = new TweetCloneDB(); var user = GetUser(context); user.Tweets.Add(new Tweet { Created = DateTime.Now, Message = message }); context.SaveChanges(); } return(RedirectToAction("RefreshBoard")); }
public ActionResult Save(Person modifiedProfile) { var context = new TweetCloneDB(); try { var existingProfile = context.People.FirstOrDefault(p => p.UserId.Equals(modifiedProfile.UserId, StringComparison.OrdinalIgnoreCase)); existingProfile.FullName = modifiedProfile.FullName; existingProfile.Email = modifiedProfile.Email; existingProfile.Password = modifiedProfile.Password; context.SaveChanges(); return(Json(string.Empty)); } catch (Exception ex) { return(Json(ex.Message)); } }
public ActionResult Delete() { try { var context = new TweetCloneDB(); String userId = Session["userid"] as String; var user = context.People.FirstOrDefault(p => p.UserId.Equals(userId, StringComparison.OrdinalIgnoreCase)); context.Tweets.RemoveRange(user.Tweets); context.Followings.RemoveRange(user.Followers); context.Followings.RemoveRange(user.Followings); context.People.Remove(user); context.SaveChanges(); return(PartialView("RemoveProfileResult")); } catch (Exception ex) { return(Json(false)); } }
public ActionResult Follow(string followId) { if (!string.IsNullOrEmpty(followId)) { var context = new TweetCloneDB(); var user = GetUser(context); var followUser = context.People.FirstOrDefault(p => p.UserId.Equals(followId, StringComparison.OrdinalIgnoreCase)); if (followUser != null) { context.Followings.Add(new Following { UserId = followId, FollowingId = user.UserId }); } context.SaveChanges(); } return(RedirectToAction("RefreshInfo")); }
public ActionResult Signup(Person signup) { var context = new TweetCloneDB(); try { var foundUser = context.People.FirstOrDefault(p => p.UserId.Equals(signup.UserId, StringComparison.OrdinalIgnoreCase)); if (foundUser != null) { return(Json("User already exist!")); } signup.Joined = DateTime.Now; signup.Active = true; context.People.Add(signup); context.SaveChanges(); Session["userid"] = signup.UserId; Session["fullname"] = signup.FullName; return(Json(string.Empty)); } catch (DbEntityValidationException ex) { var errors = new StringBuilder(); foreach (var e in ex.EntityValidationErrors) { foreach (var err in e.ValidationErrors) { errors.AppendFormat("{0}<br>", err.ErrorMessage); } } return(Json(errors.ToString())); } catch (Exception ex) { return(Json(ex.Message)); } }