public ActionResult FetchPeople(string data)
        {
            // Authenticate first
            var result = AuthenticateUser();
            if (!result.IsValid) return AuthorizationError(result);

            BaseMessage dataIn = BaseMessage.createFromString(data);
            MobilePostSearch mps = JsonConvert.DeserializeObject<MobilePostSearch>(dataIn.data);

            BaseMessage br = new BaseMessage();

            var m = new SearchModel(mps.name, mps.comm, mps.addr);

            br.setNoError();
            br.count = m.Count;

            switch (dataIn.device)
            {
                case BaseMessage.API_DEVICE_ANDROID:
                    {
                        Dictionary<int, MobilePerson> mpl = new Dictionary<int, MobilePerson>();

                        MobilePerson mp;

                        foreach (var item in m.ApplySearch().OrderBy(p => p.Name2).Take(100))
                        {
                            mp = new MobilePerson().populate(item);
                            mpl.Add(mp.id, mp);
                        }

                    br.data = SerializeJSON(mpl, dataIn.version);
                        break;
                    }

                case BaseMessage.API_DEVICE_IOS:
                    {
                        List<MobilePerson> mp = new List<MobilePerson>();

                        foreach (var item in m.ApplySearch().OrderBy(p => p.Name2).Take(100))
                        {
                            mp.Add(new MobilePerson().populate(item));
                        }

                    br.data = SerializeJSON(mp, dataIn.version);
                        break;
                    }
            }

            return br;
        }
Exemple #2
0
        public ActionResult FetchPeople(string data)
        {
            // Authenticate first
            var authError = Authenticate();
            if (authError != null) return authError;

            // Check to see if type matches
            BaseMessage dataIn = BaseMessage.createFromString(data);
            if (dataIn.type != BaseMessage.API_TYPE_PEOPLE_SEARCH)
                return BaseMessage.createTypeErrorReturn();

            // Everything is in order, start the return
            MobilePostSearch mps = JsonConvert.DeserializeObject<MobilePostSearch>(dataIn.data);

            BaseMessage br = new BaseMessage();

            var m = new CmsWeb.Models.iPhone.SearchModel(mps.name, mps.comm, mps.addr);

            br.error = 0;
            br.type = BaseMessage.API_TYPE_PEOPLE_SEARCH;
            br.count = m.Count;

            switch (dataIn.device)
            {
                case BaseMessage.API_DEVICE_ANDROID:
                    {
                        Dictionary<int, MobilePerson> mpl = new Dictionary<int, MobilePerson>();

                        MobilePerson mp;

                        foreach (var item in m.ApplySearch().OrderBy(p => p.Name2).Take(20))
                        {
                            mp = new MobilePerson().populate(item);
                            mpl.Add(mp.id, mp);
                        }

                        br.data = JsonConvert.SerializeObject(mpl);
                        break;
                    }

                case BaseMessage.API_DEVICE_IOS:
                    {
                        List<MobilePerson> mp = new List<MobilePerson>();

                        foreach (var item in m.ApplySearch().OrderBy(p => p.Name2).Take(20))
                        {
                            mp.Add(new MobilePerson().populate(item));
                        }

                        br.data = JsonConvert.SerializeObject(mp);
                        break;
                    }

                default: break;
            }

            return br;
        }