public PartialViewResult _EditGroupScrollPosts(EditGroupDataModel egdm, string IncreaseOffset)
 {
     var offFlag = Boolean.Parse(IncreaseOffset);
     Group g = db.Groups.FirstOrDefault(k => k.GroupID == egdm.Group.GroupID);
     egdm.Group = g;
     int off = 0;
     int offset = int.Parse(Request.Form[0]);
     if (offFlag)
     {
         off = Math.Min(offset + 5, g.PostCount - 5);
     }
     else
     {
         off = Math.Max(offset - 5, 0);
     }
     egdm.Offset = off;
     return PartialView("_EditGroupOptions", egdm);
 }
 public PartialViewResult _EditGroupRemovePost(EditGroupDataModel egdm, int PostId = 0)
 {
     Group g = db.Groups.FirstOrDefault(k => k.GroupID == egdm.Group.GroupID);
     if (PostId == 0)
     {
         PostId = int.Parse(Request.Form[0]);
     }
     try
     {
         Post post = g.Posts.First(p => p.PostID == PostId);
         db.Posts.Remove(post);
         db.SaveChanges();
     }
     catch
     {
         ModelState.AddModelError("DeletingPostId", "No post with id \"" + PostId.ToString() + "\" exists in this group.");
     }
     egdm.Group = g;
     return PartialView("_EditGroupOptions", egdm);
 }
 public PartialViewResult _EditGroupRemovePostByID(EditGroupDataModel egdm)
 {
     return _EditGroupRemovePost(egdm, egdm.DeletingPostId);
 }
 public ActionResult _EditGroupOptions(int GroupId)
 {
     if (ur.IsOwnerOf(GroupId))
     {
         EditGroupDataModel egdm = new EditGroupDataModel();
         Group g = db.Groups.FirstOrDefault(k => k.GroupID == GroupId);
         egdm.Group = g;
         egdm.Offset = 0;
         return PartialView(egdm);
     }
     return _ViewGroupData(GroupId);
 }
 public PartialViewResult _EditGroupMakePublic(EditGroupDataModel egdm)
 {
     var g = db.Groups.FirstOrDefault(k => k.GroupID == egdm.Group.GroupID);
     egdm.Group = g;
     g.IsPrivate = false;
     db.SaveChanges();
     return PartialView("_EditGroupOptions", egdm);
 }
 public PartialViewResult _EditGroupBanUser(EditGroupDataModel egdm, string BanUserName)
 {
     Group g = db.Groups.FirstOrDefault(k => k.GroupID == egdm.Group.GroupID);
     try
     {
         User toinvite = db.Users.First(d => d.UserName == BanUserName);
         if (!g.Users2.Contains(toinvite))
         {
             ModelState.AddModelError("BanUserName", "\"" + BanUserName + "\" is not subscribed to this group.");
         }
         else if (g.Users.Contains(toinvite)) // currently, moderators cannot be banned.
         {
             ModelState.AddModelError("BanUserName", "\"" + BanUserName + "\" is a moderator for the group and cannot be banned.");
         }
         else
         {
             ur.BanUserFromGroup(toinvite.UserId, g.GroupID);
             ur.Save();
         }
     }
     catch
     {
         ModelState.AddModelError("BanUserName", "No user by name \"" + BanUserName + "\" exists");
     }
     egdm.Group = g;
     return PartialView("_EditGroupOptions", egdm);
 }
 public PartialViewResult _EditGroupAddMod(EditGroupDataModel egdm, string ModUserName)
 {
     Group g = db.Groups.FirstOrDefault(k => k.GroupID == egdm.Group.GroupID);
     try
     {
         User toinvite = db.Users.First(d => d.UserName == ModUserName);
         if (!g.Users2.Contains(toinvite)) // the user is not subscribed to the group and cannot be moderator
         {
             ModelState.AddModelError("ModUserName", "\"" + ModUserName + "\" must be subscribed to this group to be a mod.");
         }
         else if (g.Users.Contains(toinvite)) // already a moderator!
         {
             ModelState.AddModelError("ModUserName", "\"" + ModUserName + "\" is already a moderator for this group.");
         }
         else
         {
             ur.GiveUserOwnership(toinvite.UserId, g.GroupID);
             ur.Save();
         }
     }
     catch
     { // user does not exist!
         ModelState.AddModelError("ModUserName", "No user by name \"" + ModUserName + "\" exists");
     }
     egdm.Group = g;
     return PartialView("_EditGroupOptions", egdm);
 }
 public PartialViewResult _EditGroupAddInvite(EditGroupDataModel egdm, string InviteUserName)
 {
     Group g = db.Groups.FirstOrDefault(k => k.GroupID == egdm.Group.GroupID);
     try
     {
         User toinvite = db.Users.First(d => d.UserName == InviteUserName);
         if (g.Users2.Contains(toinvite)) // already subscribed
         {
             ModelState.AddModelError("InviteUserName", "\"" + InviteUserName + "\"That user is already subscribed to the group.");
         }
         else if (g.Users1.Contains(toinvite)) // already invited to join
         {
             ModelState.AddModelError("InviteUserName", "\"" + InviteUserName + "\" is already invited to the group.");
         }
         else
         {
             ur.AllowUserSubscribeToGroup(toinvite.UserId, g.GroupID);
             ur.Save();
         }
     }
     catch
     { // oops, that user does not exist!
         ModelState.AddModelError("InviteUserName", "No user by name \"" + InviteUserName + "\" exists");
     }
     egdm.Group = g;
     return PartialView("_EditGroupOptions", egdm);
 }