// PROFILE PAGE
 // Helper method FillProfileModel
 // Create a new ProfileModel from the currentuser
 //      currentoffset: offset in the post table in the profile
 private ProfileModel FillProfileModel(int currentoffset = 0)
 {
     ProfileModel pm = new ProfileModel();
     User u = ur.GetUser();
     var written = ur.GetCreatedPosts();
     var blocked = ur.GetBlockedUsers();
     var blockposts = ur.GetBlockedPosts();
     pm.CurrentUser = u;
     pm.WrittenPosts = written.ToList();
     pm.Blocks = blocked.ToList();
     pm.BlockedPosts = blockposts.ToList();
     pm.Offset = currentoffset;
     pm.UserToBlock = "";
     return pm;
 }
 public PartialViewResult _ProfileScrollPosts(ProfileModel pm, string IncreaseOffset)
 {
     var written = ur.GetCreatedPosts();
     var offFlag = Boolean.Parse(IncreaseOffset);
     int off = 0;
     int offset = int.Parse(Request.Form[0]);
     if (offFlag)
     {
         off = Math.Min(offset + 5, written.Count() - 5);
     }
     else
     {
         off = Math.Max(offset - 5, 0);
     }
     return PartialView("_ViewProfile", FillProfileModel(off));
 }
 public PartialViewResult _ProfileChangeDescription(ProfileModel pm)
 {
     ur.ChangeDescription(pm.CurrentUser.ProfileDescription);
     ur.Save();
     return PartialView("_ViewProfile", FillProfileModel(pm.Offset));
 }
 public PartialViewResult _ProfileRemovePost(ProfileModel pm, int CurrOffset)
 {
     int PostId = int.Parse(Request.Form[0]);
     try
     {
         Post post = db.Posts.First(p => p.PostID == PostId);
         db.Posts.Remove(post);
         db.SaveChanges();
     }
     catch
     {
         ModelState.AddModelError("DeletingPostId", "No post with id \"" + PostId.ToString() + "\" exists.");
     }
     return PartialView("_ViewProfile", FillProfileModel(CurrOffset));
 }
 public PartialViewResult _ProfileBlockuser(ProfileModel pm, int CurrOffset)
 {
     User u = ur.GetUser();
     try
     {
         if (pm.UserToBlock == "" || pm.UserToBlock == null)
             ModelState.AddModelError("UserToBlock", "You must enter a valid username.");
         else if (pm.UserToBlock == u.UserName)
             ModelState.AddModelError("UserToBlock", "You cannot block yourself!");
         else
         {
             User b = db.Users.First(d => d.UserName == pm.UserToBlock);
             if (u.User1.Contains(b))
                 ModelState.AddModelError("UserToBlock", "You are already blocking \"" + pm.UserToBlock + "\"");
             else
                 return _ProfileManageBlocks(pm.UserToBlock, CurrOffset, true);
         }
     }
     catch
     {
         ModelState.AddModelError("UserToBlock", "No user by name \"" + pm.UserToBlock + "\" exists.");
     }
     return PartialView("_ViewProfile", FillProfileModel(CurrOffset));
 }