public ActionResult CreateUser(string data) { BaseMessage dataIn = BaseMessage.createFromString(data); MobilePostCreate mpc = JsonConvert.DeserializeObject<MobilePostCreate>(dataIn.data); MobileAccount account = MobileAccount.Create(mpc.first, mpc.last, mpc.email, mpc.phone, mpc.dob); var br = new BaseMessage(); // todo: notify user based on ResultCode if (account.Result == MobileAccount.ResultCode.BadEmailAddress || account.Result == MobileAccount.ResultCode.FoundMultipleMatches) { br.setError(BaseMessage.API_ERROR_CREATE_FAILED); } else { br.setNoError(); br.data = account.User.Username; } 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.setError(BaseMessage.API_ERROR_PERSON_NOT_FOUND); br.data = "Person not found."; return br; } br.setNoError(); br.count = 1; if (dataIn.device == BaseMessage.API_DEVICE_ANDROID) { br.data = SerializeJSON(new MobilePerson().populate(person), dataIn.version); } else { List<MobilePerson> mp = new List<MobilePerson>(); mp.Add(new MobilePerson().populate(person)); br.data = SerializeJSON(mp, dataIn.version); } return br; }
public ActionResult FetchPerson(string data) { // Authenticate first if (!Auth()) return BaseMessage.createErrorReturn("Authentication failed, please try again", BaseMessage.API_ERROR_INVALID_CREDENTIALS); BaseMessage dataIn = BaseMessage.createFromString(data); BaseMessage br = new BaseMessage(); var person = DbUtil.Db.People.SingleOrDefault(p => p.PeopleId == dataIn.argInt); if (person == null) { br.setError(BaseMessage.API_ERROR_PERSON_NOT_FOUND); br.data = "Person not found."; return br; } br.setNoError(); br.count = 1; if (dataIn.device == BaseMessage.API_DEVICE_ANDROID) { br.data = SerializeJSON(new CheckInPerson().populate(person), dataIn.version); } else { List<CheckInPerson> mp = new List<CheckInPerson>(); mp.Add(new CheckInPerson().populate(person)); br.data = SerializeJSON(mp, dataIn.version); } return br; }