public ActionResult FetchPerson(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_PERSON_REFRESH) { return(BaseMessage.createTypeErrorReturn()); } // Everything is in order, start the return MobilePostFetchPerson mpfs = JsonConvert.DeserializeObject <MobilePostFetchPerson>(dataIn.data); BaseMessage br = new BaseMessage(); var person = DbUtil.Db.People.SingleOrDefault(p => p.PeopleId == mpfs.id); if (person == null) { br.error = 1; br.data = "Person not found."; return(br); } br.error = 0; br.type = BaseMessage.API_TYPE_PERSON_REFRESH; br.count = 1; if (dataIn.device == BaseMessage.API_DEVICE_ANDROID) { br.data = JsonConvert.SerializeObject(new MobilePerson().populate(person)); } else { List <MobilePerson> mp = new List <MobilePerson>(); mp.Add(new MobilePerson().populate(person)); br.data = JsonConvert.SerializeObject(mp); } return(br); }
public ActionResult FetchPerson(string data) { // Authenticate first var result = AuthenticateUser(); if (!result.IsValid) { return(AuthorizationError(result)); } BaseMessage dataIn = BaseMessage.createFromString(data); MobilePostFetchPerson mpfs = JsonConvert.DeserializeObject <MobilePostFetchPerson>(dataIn.data); BaseMessage br = new BaseMessage(); var person = DbUtil.Db.People.SingleOrDefault(p => p.PeopleId == mpfs.id); if (person == null) { br.error = 1; br.data = "Person not found."; return(br); } br.error = 0; br.count = 1; if (dataIn.device == BaseMessage.API_DEVICE_ANDROID) { br.data = JsonConvert.SerializeObject(new MobilePerson().populate(person)); } else { List <MobilePerson> mp = new List <MobilePerson>(); mp.Add(new MobilePerson().populate(person)); br.data = JsonConvert.SerializeObject(mp); } return(br); }