public ActionResult AddFriendAccepted() { string u1 = Request.Form["u1"].ToString(); string u2 = Request.Form["u2"].ToString(); int id = Convert.ToInt32(Request.Form["id"]); friendsDal fDal = new friendsDal(); List <Friends> checkFriends = (from x in fDal.FriendsLst where (x.username.Equals(u1) && x.friendUsername.Equals(u2)) || (x.username.Equals(u2) && x.friendUsername.Equals(u1)) select x).ToList <Friends>(); Friends f = new Friends(); f.username = u1; f.friendUsername = u2; fDal.FriendsLst.Add(f); fDal.SaveChanges(); Notifications n = new Notifications(); notificationsDal nDal = new notificationsDal(); List <Notifications> nots = (from x in nDal.nLst select x).ToList(); List <Notifications> prev = (from x in nDal.nLst where x.id == id select x).ToList <Notifications>(); nDal.nLst.RemoveRange(nDal.nLst.Where(x => x.id == id)); nDal.SaveChanges(); n.id = id; n.status = "Accepted"; n.type = "Friend Request"; n.username = u1; n.uFrom = u2; n.dateSent = DateTime.Now; n.dateSent = n.dateSent.Date; nDal.nLst.Add(n); nDal.SaveChanges(); n = new Notifications { dateSent = DateTime.UtcNow, id = nots.Count() + 1, type = "Friend Request", status = "Return Accepted", username = u2, uFrom = u1 }; nDal.nLst.Add(n); nDal.SaveChanges(); return(RedirectToAction("showNotifications", "Notifications")); }
public ActionResult DeleteUser(string delete) { profileDal pdal = new profileDal(); UsersStatusDal usdal = new UsersStatusDal(); notificationsDal ndal = new notificationsDal(); friendsDal fdal = new friendsDal(); String toDelete; try { toDelete = Request.Form["row"].ToString(); } catch (Exception) { toDelete = delete; } udal.userLst.RemoveRange(udal.userLst.Where(x => x.username.Equals(toDelete))); adal.adminsLst.RemoveRange(adal.adminsLst.Where(x => x.username.Equals(toDelete))); pdal.profilesList.RemoveRange(pdal.profilesList.Where(x => x.username.Equals(toDelete))); usdal.statuses.RemoveRange(usdal.statuses.Where(x => x.username.Equals(toDelete))); ndal.nLst.RemoveRange(ndal.nLst.Where(x => x.username.Equals(toDelete) || x.uFrom.Equals(toDelete))); fdal.FriendsLst.RemoveRange(fdal.FriendsLst.Where(x => x.username.Equals(toDelete))); fdal.FriendsLst.RemoveRange(fdal.FriendsLst.Where(x => x.friendUsername.Equals(toDelete))); udal.SaveChanges(); adal.SaveChanges(); pdal.SaveChanges(); usdal.SaveChanges(); ndal.SaveChanges(); fdal.SaveChanges(); return(RedirectToAction("usersList", "Admin")); }
public ActionResult joinAccepted() { string username = Request.Form["username"]; string uFrom = Request.Form["uFrom"]; int id = Convert.ToInt32(Request.Form["id"]); Notifications n = new Notifications(); notificationsDal nDal = new notificationsDal(); int size = (from x in nDal.nLst select x).ToList <Notifications>().Count() + 1; List <Notifications> tmp = (from x in nDal.nLst where x.id == id select x).ToList <Notifications>(); nDal.nLst.RemoveRange(nDal.nLst.Where(x => x.id == id)); nDal.SaveChanges(); tmp[0].status = "Accepted"; nDal.nLst.Add(tmp[0]); nDal.SaveChanges(); n.id = id; n.dateSent = DateTime.Now.Date; n.status = "Return Accepted"; n.type = tmp[0].type; n.uFrom = username; n.username = uFrom; nDal.nLst.Add(n); nDal.SaveChanges(); int mid = Convert.ToInt32((tmp[0].type.Split(' '))[1]); userMomentDal mDal = new userMomentDal(); userMoments uM = new userMoments(); momentsDal d = new momentsDal(); string groupName = (from x in d.momentsLst where x.mid == mid select x).ToList <moments>()[0].mName; int tableId = (from x in mDal.userMomentLST select x).ToList <userMoments>().Count() + 1; uM.id = tableId; uM.GroupName = groupName; uM.mid = mid; uM.uType = "User"; uM.username = uFrom; mDal.userMomentLST.Add(uM); mDal.SaveChanges(); return(RedirectToAction("showNotifications", "Notifications")); }
public ActionResult AddFriend(String id) { notificationsDal nDal = new notificationsDal(); List <Notifications> tmp = (from x in nDal.nLst select x).ToList <Notifications>(); int size = tmp.Count(); Notifications newNoti = new Notifications(); newNoti.username = id; newNoti.status = "Not Accepted"; newNoti.uFrom = Session["CurrentUsername"].ToString(); newNoti.dateSent = DateTime.Now; newNoti.type = "Friend Request"; newNoti.id = size + 1; nDal.nLst.Add(newNoti); nDal.SaveChanges(); friendsDal fDal = new friendsDal(); String uname = Session["CurrentUsername"].ToString(); List <Friends> friends1 = (from x in fDal.FriendsLst where x.username.Equals(uname) select x).ToList <Friends>(); List <Friends> friends2 = (from x in fDal.FriendsLst where x.friendUsername.Equals(uname) select x).ToList <Friends>(); IEnumerable <Friends> friendAll = friends1.Union(friends2); List <String> friends = new List <string>(); foreach (var f in friendAll) { if (f.username.Equals(uname)) { friends.Add(f.friendUsername); } else { friends.Add(f.username); } } //IEnumerable<Friends> friends = friends1.Union(friends2); profileDal pDal = new profileDal(); List <Profile> profiles = (from x in pDal.profilesList where friends.Contains <String>(x.username) select x).ToList <Profile>(); return(View("MyFriends", profiles)); }
public ActionResult JoinRequest() { userMomentDal mDal = new userMomentDal(); int mid = Convert.ToInt32(Request.Form["mid"]); List <userMoments> findAdmin = (from x in mDal.userMomentLST where x.mid == mid && x.uType.Equals("Admin") select x).ToList <userMoments>(); string adminUsr = findAdmin[0].username; notificationsDal nDal = new notificationsDal(); Notifications n = new Notifications(); n.uFrom = UserController.user.username; n.username = adminUsr; n.dateSent = DateTime.Now.Date; n.id = (from x in nDal.nLst select x).ToList <Notifications>().Count + 1; n.type = "Join " + mid; n.status = "Not Accepted"; nDal.nLst.Add(n); nDal.SaveChanges(); return(RedirectToAction("UserMoments", "User")); }
public ActionResult SendMessage() { string message = Request.Form["mess"].ToString(); notificationsDal dal = new notificationsDal(); Notifications n = new Notifications(); n.username = "******"; n.id = (from x in dal.nLst select x).ToList <Notifications>().Count() + 1; n.status = message; n.dateSent = DateTime.Now.Date; n.type = "Admin Message"; n.uFrom = "Admin"; try { dal.nLst.Add(n); dal.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.Message); ViewData["ErrorMessage"] = "Error While sending message, try again in a moment"; } return(View("NotificationView")); }
public JsonResult CheckLogInInformation(string username1) { usersDal db = new usersDal(); userMomentDal umd = new userMomentDal(); //Momentmaxnumber string getmax = Session["getthemaxnumber"].ToString(); int value = Convert.ToInt32(getmax); int getmidnumber = Convert.ToInt32(Session["getmidd"]); System.Threading.Thread.Sleep(2000); var GetIfUserExist = db.userLst.Where(x => x.username == username1).SingleOrDefault(); List <userMoments> usersingroup = (from tmp in umd.userMomentLST where tmp.mid.Equals(getmidnumber) select tmp).ToList <userMoments>(); if (usersingroup.Count() <= value) { if (GetIfUserExist != null) { users oh = new users(); oh = GetUser(); if (username1 != oh.username) { Notifications n = new Notifications(); notificationsDal nDal = new notificationsDal(); int id = (from x in nDal.nLst select x).ToList <Notifications>().Count() + 1; n.dateSent = DateTime.Now.Date; n.id = id; n.status = "Not Accepted"; n.type = "invite " + Session["mid"]; n.username = username1; n.uFrom = oh.username; nDal.nLst.Add(n); nDal.SaveChanges(); /* * userMoments usermoment = new userMoments(); * usermoment.id = 1; * usermoment.mid = Convert.ToInt32(Session["mid"]); * usermoment.GroupName = Session["MomentName1"].ToString(); * usermoment.username = username1; * usermoment.uType = "User"; * umd.userMomentLST.Add(usermoment); * umd.SaveChanges(); */ return(Json(1)); } else { return(Json(2)); } } else { return(Json(0)); } } else { return(Json(3)); } }