Пример #1
0
 public static Object insert_lbxFriends(friend f)
 {
     using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString))
     {
         connection.Open();
         using (SqlCommand command = new SqlCommand("addFriend", connection))
         {
             command.CommandType = CommandType.StoredProcedure;
             command.Parameters.AddWithValue("@firstname", f.firstname);
             command.Parameters.AddWithValue("@lastname", f.lastname);
             return command.ExecuteScalar();
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Accepts a friend request between the specified
        /// id (the source) and the logged in user (the destination)
        /// </summary>
        /// <param name="id">The id of the source of the friend request</param>
        /// <returns>True if successful, false otherwise</returns>
        public Boolean AcceptFriendRequest(int id)
        {
            // Ssame user?
            if (id == WebSecurity.CurrentUserId)
                return false;

            // Find the pending request
            friend_pending pending = (from f in _dbContext.friend_pending
                                      where f.source_id == id && f.destination_id == WebSecurity.CurrentUserId
                                      select f).FirstOrDefault();
            if (pending == null)
                return false;

            // Remove pending, then add friendships in both directions
            _dbContext.friend_pending.Remove(pending);

            friend f1 = new friend()
            {
                source_id = id,
                destination_id = WebSecurity.CurrentUserId,
                request_date = pending.request_date,
                friended_date = DateTime.Now
            };

            friend f2 = new friend()
            {
                source_id = WebSecurity.CurrentUserId,
                destination_id = id,
                request_date = pending.request_date,
                friended_date = f1.friended_date
            };

            _dbContext.friend.Add(f1);
            _dbContext.friend.Add(f2);

            _unitOfWork.AchievementRepository.CheckFriendSystemAchievements(WebSecurity.CurrentUserId);
            _unitOfWork.AchievementRepository.CheckFriendSystemAchievements(f1.source_id);
            LoggerModel logFriendRequest = new LoggerModel()
            {
                Action = Logger.PlayerFriendLogType.AcceptRequest.ToString(),
                UserID = WebSecurity.CurrentUserId,
                IPAddress = HttpContext.Current.Request.UserHostAddress,
                TimeStamp = DateTime.Now,
                ID1 = id,
                IDType1 = Logger.LogIDType.User.ToString()
            };
            Logger.LogSingleEntry(logFriendRequest, _dbContext);
            _dbContext.SaveChanges();
            return true;
        }
        public IHttpActionResult Deletefriend(int id)
        {
            friend friend = db.friends.Find(id);

            if (friend == null)
            {
                return(NotFound());
            }

            db.friends.Remove(friend);
            db.SaveChanges();

            return(Ok(friend));
        }
Пример #4
0
 public static Object insert_lbxFriends(friend f)
 {
     using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString))
     {
         connection.Open();
         using (SqlCommand command = new SqlCommand("addFriend", connection))
         {
             command.CommandType = CommandType.StoredProcedure;
             command.Parameters.AddWithValue("@firstname", f.firstname);
             command.Parameters.AddWithValue("@lastname", f.lastname);
             return(command.ExecuteScalar());
         }
     }
 }
Пример #5
0
        // GET: Friends/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            friend friend = db.friends.Find(id);

            if (friend == null)
            {
                return(HttpNotFound());
            }
            return(View(friend));
        }
Пример #6
0
        public void AddFriend(long subdomainid, long friendsubdomainid)
        {
            //check if friend exists
            if (!IsFriend(subdomainid, friendsubdomainid))
            {
                friend f = new friend {
                    subdomainid = subdomainid, friendsubdomainid = friendsubdomainid
                };
                db.friends.InsertOnSubmit(f);

                // update total contacts count for both ppl
                UpdateCounters(subdomainid, 1, CounterType.CONTACTS_PUBLIC);
                UpdateCounters(friendsubdomainid, 1, CounterType.CONTACTS_PUBLIC);
            }
        }
Пример #7
0
        public void ConfimRequest()
        {
            string currid  = Request.Params["id"].ToString();
            int    id      = int.Parse(Request.Params["id1"].ToString());
            int    notifID = int.Parse(Request.Params["notifID"]);
            user   us      = Session["User" + currid] as user;
            //delete current notification
            notification not = db.notifications.Where(n => n.id == notifID).ToList().First();

            db.notifications.Remove(not);
            db.SaveChanges();
            //sent response notification
            notification notif = new notification();

            notif.user_id   = id;
            notif.sender_id = us.id;
            notif.text_id   = 4;
            notif.state     = 1;
            notif.datetime  = DateTime.Now;
            db.notifications.Add(notif);
            db.SaveChanges();
            //add to friend;
            friend friends = new friend();

            friends.user_id        = us.id;
            friends.friend_user_id = id;
            db.friends.Add(friends);
            //add to followers
            follower folow = new follower();

            folow.user_id     = us.id;
            folow.follower_id = id;
            db.followers.Add(folow);
            follower folow2 = new follower();

            folow2.user_id     = id;
            folow2.follower_id = us.id;
            db.followers.Add(folow2);
            try
            {
                db.SaveChanges();
                Response.Write("ok");
            }
            catch (Exception e)
            {
                Response.Write("Sorry something wen't wrong - " + e.InnerException.ToString() + "x=" + id);
            }
        }
Пример #8
0
        public friend Get_Friend(int id_Friend)
        {
            friend Friend = new friend();

            try
            {
                Friend = (from data in _db.friends
                          where (data.Status == true && data.id == id_Friend)
                          select data).FirstOrDefault();
            }
            catch (Exception ex)
            {
                throw;
            }
            return(Friend);
        }
Пример #9
0
        public ErrorMessage AddFriend(string userBid)
        {
            if (currentUser == null)
                return ErrorMessage.ERROR;
            if (userBid == currentUser.userId)
                return ErrorMessage.ERROR;
            UserHandler BHandler = new UserHandler();
            if (BHandler.SetCurrentUserById(userBid) == ErrorMessage.NOT_EXIST)
                return ErrorMessage.NOT_EXIST;
            if (currentUser.friend.Any(ff => ff.userB == userBid) || currentUser.friend1.Any(ff => ff.userA == userBid))
                return ErrorMessage.ALREADY_EXIST;

            friend newRecord=new friend { userA=currentUser.userId,userB=userBid};
            currentUser.friend.Add(newRecord);
            return ErrorMessage.OK;
        }
Пример #10
0
 private void Sql()//显示好友
 {
     try
     {
         conn     = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
         friendsW = new ArrayList();
         friendsB = new ArrayList();
         string     str = string.Format(@"select Friends.UserID, Friends.FriendNick, Friends.FriendNotes, Friends.FriendState, Friends.FriendClassification, Headpic, signatures from Friends,[User] where Friends.FriUserID=[User].UserID and [User].UserID in (select Friends.FriUserID from Friends where UserID ='" + UserID + "')");
         SqlCommand cmd = new SqlCommand(str, conn);
         if (conn != null && conn.State != ConnectionState.Open)
         {
             conn.Open();
         }
         SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
         while (dr.Read())
         {
             friend a = new friend();
             a.Friendnick           = dr["FriendNick"].ToString();
             a.Friendnotes          = dr["FriendNotes"].ToString();
             a.FriuserID            = dr["UserID"].ToString();
             a.FriendState          = dr["FriendState"].ToString();
             a.FriendUrl            = dr["HeadPic"].ToString();
             a.FriendClassification = dr["FriendClassification"].ToString();
             a.Signatures           = dr["Signatures"].ToString();
             if (!a.FriendClassification.Contains("黑名单"))
             {
                 friendsW.Add(a);
             }
             else
             {
                 friendsB.Add(a);
             }
         }
         dr.Close();
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         if (conn.State != ConnectionState.Closed)
         {
             conn.Close();
         }
     }
 }
Пример #11
0
        public void UnFriend()
        {
            string currId = Request.Params["id"].ToString();
            int    id     = int.Parse(Request.Params["id1"]);
            user   us     = Session["User" + currId] as user;
            friend friend = new friend();

            friend = db.friends.Where(fr => (fr.friend_user_id == id && fr.user_id == us.id) || (fr.user_id == id && fr.friend_user_id == us.id)).ToList().First();
            try
            {
                db.friends.Remove(friend);
                db.SaveChanges();
            }
            catch (Exception e)
            {
                Response.Write("Sorry something wen't wrong - " + e.InnerException.ToString() + "x=" + id);
            }
            Redirect("/Chrono/index/" + id);
        }
Пример #12
0
        public async Task <IHttpActionResult> SendRequest(friend friend)
        {
            if (!ModelState.IsValid || friend.friendId == friend.UserId)
            {
                return(BadRequest(ModelState));
            }
            db.send_friend_request(friend.UserId, friend.friendId, friend.since);
            //db.friends.Add(friend);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (friendExists(friend.UserId, friend.friendId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }
            var new_notifi = new cls_notifi {
                source_name  = "user",
                source_id    = friend.friendId,
                image        = db.AspNetUsers.FirstOrDefault(x => x.Id == friend.friendId).Photo,//"no image",
                body_English = db.AspNetUsers.FirstOrDefault(x => x.Id == friend.friendId).UserName + " send you a friend request",
                body_Arabic  = "قام " + db.AspNetUsers.FirstOrDefault(x => x.Id == friend.friendId).UserName + " بارسال طلب صداقة اليك",

                timestamp = DateTime.Now,
                readed    = false
            };

            await Push(new_notifi, "notifications/" + friend.UserId.ToString() + "/" + DateTime.UtcNow.ToString("dd-MM-yyyy"));

            PushNotifi(db.AspNetUsers.FirstOrDefault(x => x.Id == friend.UserId).DeviceToken, "New Friend Request", new_notifi.body_English, "user", friend.friendId);
            //return RedirectToRoute("~/rpc/notifi/push", new { notifi= new_notifi, path = "notifications/" + friend.UserId.ToString() + "/friends" });
            return(CreatedAtRoute("DefaultApi", new { id = friend.UserId }, friend));
        }
Пример #13
0
        /// <summary>
        /// Removes a friendship between the specified
        /// id and the logged in user
        /// </summary>
        /// <param name="id">The id of the friend to remove</param>
        /// <returns>True if successful, false otherwise</returns>
        public Boolean RemoveFriend(int id)
        {
            // Find the friendships
            friend f1 = (from f in _dbContext.friend
                         where f.source_id == id && f.destination_id == WebSecurity.CurrentUserId
                         select f).FirstOrDefault();
            friend f2 = (from f in _dbContext.friend
                         where f.source_id == WebSecurity.CurrentUserId && f.destination_id == id
                         select f).FirstOrDefault();

            // If neither exists, can't remove
            if (f1 == null && f2 == null)
            {
                return(false);
            }

            LoggerModel logFriendRequest = new LoggerModel()
            {
                Action    = Logger.PlayerFriendLogType.RemoveFriend.ToString(),
                UserID    = WebSecurity.CurrentUserId,
                IPAddress = HttpContext.Current.Request.UserHostAddress,
                TimeStamp = DateTime.Now,
                ID1       = id,
                IDType1   = Logger.LogIDType.User.ToString()
            };

            Logger.LogSingleEntry(logFriendRequest, _dbContext);
            // Remove both - It should be either both or neither, but
            // during testing we may end up with just one way, so better
            // to remove the stragglers
            if (f1 != null)
            {
                _dbContext.friend.Remove(f1);
            }
            if (f2 != null)
            {
                _dbContext.friend.Remove(f2);
            }
            _dbContext.SaveChanges();
            return(true);
        }
Пример #14
0
        public void ParseICS()
        {
            string contents = File.ReadAllText(@"birthday_cal.ics");
            var    calendar = (VCalendar)CalendarObject.Parse(contents);

            this.myfriends = new ArrayList();
            foreach (var item in calendar.Children)
            {
                string name = item.Properties[1].Value;
                string id   = item.Properties[4].Value;
                string date = item.Properties[0].Value;

                friend x = new friend(name, id, date);
                myfriends.Add(x);
                //Console.WriteLine("Name : " + item.Properties[1].Value);
                //Console.WriteLine("ID : " + item.Properties[4].Value);
                //Console.WriteLine("Date : " + item.Properties[0].Value);
            }

            //MessageBox.Show("Parsing Done! See Console");
        }
Пример #15
0
        /// <summary>
        ///  function insert and update and delete User
        /// </summary>
        /// <param name="ctgr"></param>         model User
        /// <param name="action_status"></param>        status: (add; edit; insert)
        /// <returns></returns>
        public bool Add_and_Edit_Friend(friend ctgr, int action_status)
        {
            bool check = false;

            try
            {
                if (Util.Cnv_Int(ctgr.id.ToString()) > 0)
                {
                    friend data_edit = new friend();
                    data_edit = Get_Friend(ctgr.id);

                    if (action_status == Variable.action_status.is_update)
                    {            // update data
                        data_edit.FullName     = ctgr.FullName;
                        data_edit.PhoneNumber  = ctgr.PhoneNumber;
                        data_edit.Note         = ctgr.Note;
                        data_edit.UpdatedAt    = DateTime.Now;
                        data_edit.UpdatedBy    = ctgr.UpdatedBy;
                        data_edit.Relationship = ctgr.Relationship;
                    }
                    else if (action_status == Variable.action_status.is_delete)         // delete data
                    {
                        data_edit.Status = ctgr.Status;
                    }
                }
                else
                {
                    _db.friends.Add(ctgr);                                           // add data
                }
                _db.SaveChanges();
                check = true;
            }
            catch (Exception)
            {
                return(check);
            }
            return(check);
        }
Пример #16
0
        public IHttpActionResult Deletefriend(string User1, string User2)
        {
            friend friend1 = db.friends.Find(User1, User2);
            friend friend2 = db.friends.Find(User2, User1);

            if (friend1 == null && friend2 == null)
            {
                return(NotFound());
            }

            //       db.friends.Remove(friend);

            db.remove_friend_or_frequest(User1, User2);
            db.SaveChanges();
            if (friend1 == null)
            {
                return(Ok(friend2));
            }
            else
            {
                return(Ok(friend1));
            }
        }
Пример #17
0
 partial void Deletefriend(friend instance);
Пример #18
0
 partial void Updatefriend(friend instance);
Пример #19
0
 partial void Insertfriend(friend instance);
Пример #20
0
	private void attach_friend1(friend entity)
	{
		this.SendPropertyChanging();
		entity.user1 = this;
	}
 .Select(friend => (friend.Name, CloseFriends: GetCloseFriends(friend, friends, numberOfCloserFriends))).ToList();
Пример #22
0
	private void detach_friend1(friend entity)
	{
		this.SendPropertyChanging();
		entity.user1 = null;
	}
Пример #23
0
        private void addButton2_Click(object sender, EventArgs e)
        {
            var get_login = from u in database.users
                            where u.login == frndtextBox.Text
                            select new {u.u_id};

            int frnd_id = 0;
            foreach (var u in get_login)
            {
                frnd_id = u.u_id;
            }

            if (frnd_id == 0)
            {
                MessageBox.Show("No such user!", "Error!");
                return;
            }
            using (var trans = new TransactionScope())
            {
                DateTime teraz = DateTime.Now;
                friend add_friend = new friend
                {
                    u1_id = userid,
                    u2_id = frnd_id,
                    add_time = teraz
                };
                database.friends.InsertOnSubmit(add_friend);

                action fradd_act = new action
                {
                    u_id = userid,
                    act_type = "AFR",
                    action_time = teraz
                };
                database.actions.InsertOnSubmit(fradd_act);

                database.SubmitChanges();

                trans.Complete();
            }
            UpdateHistory();
            panel1.Visible = false;
        }