}//批量添加用户 public string bannered(int userid, int groupid, int id) { UserGroupToUSer us = db.UserGroupToUsers.Where(a => a.UG_UserID == userid).Where(a => a.UG_GroupID == groupid).FirstOrDefault(); us.banned = id; if (db.SaveChanges() > 0) { return("XX已经被禁言"); } else { return("解禁成功"); } }//禁言
}//禁言 public string Delete(int userid, int groupid) { UserGroupToUSer user = db.UserGroupToUsers.Where(a => a.UG_UserID == userid).Where(a => a.UG_GroupID == groupid).FirstOrDefault(); //db.Entry<UserGroupToUSer>(user).State = System.Data.Entity.EntityState.Deleted; db.UserGroupToUsers.Remove(user); if (db.SaveChanges() > 0) { return("XX用户已经被删除!"); } else { return("XX用户删除失败!"); } }//删除
public ActionResult AddGroup(FormCollection Form) { string id, Groupname, Groupintro, Groupnotice; Groupname = Request.Form["GroupName"].ToString(); Groupintro = Request.Form["GroupIntro"].ToString(); Groupnotice = Request.Form["GroupNotice"].ToString(); id = Request.Form["uid"].ToString(); //添加群表 UserGroups ug = new UserGroups(); ug.UG_CreateTime = DateTime.Now; ug.UG_Icon = "~/Images/head.jpg"; ug.UG_Introd = Groupintro; ug.UG_kName = Groupname; ug.UG_NOtice = Groupnotice; ug.UG_AdminID = (db.UserLogins.Where(a => a.id.ToString().Trim() == id.ToString().Trim()).FirstOrDefault() as UserLogin).id.ToString(); db.UserGroups.Add(ug); db.SaveChanges(); Thread.Sleep(1000); int groupid = Convert.ToInt32(db.UserGroups.Where(a => a.UG_AdminID == ug.UG_AdminID).OrderByDescending(a => a.UG_id).FirstOrDefault().UG_id); UserGroupToUSer use = new UserGroupToUSer(); use.banned = 0; use.status = "admin"; use.UG_CreateTime = DateTime.Now; use.UG_GroupID = groupid; use.UG_GroupNick = "群主"; use.UG_UserID = Convert.ToInt32(ug.UG_AdminID); db.UserGroupToUsers.Add(use); var me = (HttpContext.Session[HttpContext.Session.SessionID] as UserLogin).id; if (db.SaveChanges() > 0) { return(RedirectToAction("AddUserToG/" + groupid, "Chat")); } else { return(JavaScript("alert('群建立失败!')")); } }//创建群
}//添加用户到群视图 public string AddGroupUsers(int[] ids)//添加群用户 { List <UserInfo> us = new List <UserInfo>(); List <UserGroupToUSer> ut = new List <UserGroupToUSer>(); var id = Convert.ToInt32(Request.Params["id"].ToString().Trim()); foreach (var item in ids) { UserInfo ls = db.UserInfos.Where(a => a.userid == item).FirstOrDefault(); if (ls != null) { us.Add(ls); } else { } } foreach (var item in us) { UserGroupToUSer iu = new UserGroupToUSer(); iu.UG_CreateTime = DateTime.Now; iu.UG_GroupID = id; iu.UG_GroupNick = ""; iu.UG_id = 1; iu.UG_UserID = item.userid; iu.status = "normal"; iu.banned = 0; ut.Add(iu); } db.UserGroupToUsers.AddRange(ut); if (db.SaveChanges() > 0) { return("用户添加成功!"); } else { return("用户添加失败!"); } }