public async Task<RepositoryResponse<User>> RegisterUser(User user) { var response = new RepositoryResponse<User> { }; try { var userObject = new ParseUser() { Username = user.USERNAME, Password = user.PASSWORD }; userObject["Name"] = user.NAME; DependencyRepository DependencyContext = new DependencyRepository(); RepositoryResponse<ParseObject> Dependency = await DependencyContext.GetDependencyById(user.ID_DEPENDENCY); ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Dependency"); IEnumerable<ParseObject> result = await query.FindAsync(); var relation = userObject.GetRelation<ParseObject>("ID_Dependency"); relation.Add(Dependency.Data); await userObject.SignUpAsync(); response.Success = true; response.Data = userObject.ToUser(); // Register was successful. } catch (Exception ex) { response.Success = false; response.Error = ex; } return response; }
public async Task<RepositoryResponse<Notification>> AddNotification(Notification notification) { var response = new RepositoryResponse<Notification> { }; try { var Noti = Parse.ParseObject.Create("Notification"); #region Add Dependency Relationship DependencyRepository DependencyContext = new DependencyRepository(); RepositoryResponse<ParseObject> Dependency = await DependencyContext.GetDependencyById(notification.ID_DEPENDENCY); ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Dependency"); IEnumerable<ParseObject> result = await query.FindAsync(); #endregion #region Add City Relationship CityRepository CityContext = new CityRepository(); RepositoryResponse<ParseObject> City = await CityContext.GetCityById(notification.ID_CITY); query = new ParseQuery<ParseObject>("City"); result = await query.FindAsync(); #endregion var relation = Noti.GetRelation<ParseObject>("ID_Dependency"); relation.Add(Dependency.Data); relation = Noti.GetRelation<ParseObject>("ID_City"); relation.Add(City.Data); var message = string.Format("{0} > {1}: {2}", Dependency.Data["Name"].ToString(), City.Data["Name"].ToString(), notification.NOTIFICATION_TEXT); Noti.Add("NotificationText", message); await Noti.SaveAsync(); await Noti.SaveAsync(); var push = new ParsePush(); push.Query = from installation in ParseInstallation.Query where installation.Get<string>("City").Contains(notification.ID_CITY) select installation; push.Alert = message; await push.SendAsync(); notification.ID = Noti.ObjectId; response.Data = notification; response.Success = true; } catch (Exception ex) { response.Success = false; response.Error = ex; } return response; }