public RODResponseMessage Post([FromBody]string s)
        {
            RODResponseMessage result = new RODResponseMessage();

            string user_id = User.Identity.Name;
            handle logged_in = (from handle r in db.handles where r.userGuid.Equals(User.Identity.Name) select r).FirstOrDefault();

            // the person posting to this method has just had
            // an authorization request sent to THEM, so they need
            // to get the handle of the sender (From handle)

            handle from_handle = (from m in db.handles where m.publicKey == s && m.active == 1 select m).FirstOrDefault();
            if (from_handle == null)
            {
                result.result = 0;
                result.message = "Handle not found.";
            }
            else
            {

                follower added = (from m in db.followers where
                                  m.followerHandle.id.Equals(from_handle.id) &&
                                  m.followeeHandle.publicKey.Equals(s) &&
                                  m.active.Equals(1) select m).FirstOrDefault();

                if (added != null)
                {
                    result.message = "Person is already a contact.";
                    result.result = 0;
                    return result;
                }

                follower f = new follower();
                f.followeeId = logged_in.id;
                f.followerId = from_handle.id;
                f.active = 1;
                db.followers.Add(f);

                // now make it reciprocal too
                follower g = new follower();
                g.followeeId = from_handle.id;
                g.followerId = logged_in.id;
                g.active = 1;
                db.followers.Add(g);

                // trash the old message

                thread request = (from m in db.threads
                                  where m.toHandleId.Equals(logged_in.id) &&
                                      m.fromHandleId == from_handle.id &&
                                      m.active == 1 &&
                                      m.authorizeRequest == 1
                                  select m).FirstOrDefault();

                if (request != null)
                {
                    // it really has to exist, otherwise something
                    // sketchy is going on
                    request.active = 0;

                    db.threads.Attach(request);
                    var updated_request = db.Entry(request);

                    updated_request.Property(e => e.active).IsModified = true;
                }

                db.SaveChanges();

                result.message = "Successful add.";
                result.result = 1;
            }

            return result;
        }
예제 #2
0
        // without parameters, return all followers/contacts from the current user
        public List<followerDTO> Get()
        {
            string user_id = User.Identity.Name;
            handle logged_in = (from handle r in db.handles where r.userGuid.Equals(User.Identity.Name) select r).FirstOrDefault();

            // fake the dash

            follower dash = new follower();

            dash.active = 1;
            dash.followeeHandle = new handle();
            dash.followeeHandle.name = "dash";
            dash.followeeHandle.publicKey = "1";

            // fake the wire

            //follower wire = new follower();

            //wire.active = 1;
            //wire.followeeHandle = new handle();
            //wire.followeeHandle.name = "the wire";
            //wire.followeeHandle.publicKey = "2";

            List<follower> followers = (from follower m in db.followers where m.followerHandle.id.Equals(logged_in.id) && m.active.Equals(1) select m).ToList();

            //followers.Insert(0, wire);
            followers.Insert(0, dash);

            List<followerDTO> followersDTO = Mapper.Map<List<follower>, List<followerDTO>>(followers);

            foreach (followerDTO d in followersDTO)
            {

                if(d.followeeHandle.name == "dash") {

                    thread yourMostRecentDash = (from m in db.threads
                                                 where
                                                     m.fromHandleId == logged_in.id &&
                                                     m.active == 1 && m.toHandleId == 1
                                                 orderby m.id descending
                                                 select m).FirstOrDefault();

                    if (yourMostRecentDash != null)
                    {
                        d.mostRecentSnap = yourMostRecentDash.groupKey;
                    }

                } else {

                    thread t = (from m in db.threads
                                where m.fromHandleId == d.followeeId
                                    && m.active == 1 && m.toHandleId == 1
                                orderby m.id descending
                                select m).FirstOrDefault();

                    if (t != null)
                    {
                        d.mostRecentSnap = t.groupKey;
                    }

                }
            }

            return followersDTO;
        }