public async Task <UpdateResult <T> > Push <T>(string userToken, Predicate <T> criteria = null) where T : BaseModel { var headers = new Dictionary <string, string>(Connection.Headers) { { "user-token", userToken } }; criteria = criteria ?? (a => true); var context = PersistenceContextFactory.CreateFor <T>(); var items = await Asyncer.Async(() => context.LoadDeletedObjects()); var result = new UpdateResult <T>(); foreach (var item in items.Where(i => criteria(i))) { var url = Connection.GenerateTableUrl <T>(item.ObjectId); var json = await Caller.Delete(url, headers); var asDictionary = Serializer.AsDictionary(json); if (asDictionary.ContainsKey(DeletionTime)) { context.Purge(item.ObjectId); result.Success(item, item.ObjectId); } else { var parsed = ResponseParser.Parse <T>(json); result.Failed(item, parsed.ToString()); } } return(result); }
public Task <IEnumerable <Assessment> > GetAssessments(string disasterId) { var context = PersistenceContextFactory.CreateFor <Assessment>(); var assessments = context.LoadAll().ToList(); return(Asyncer.Async(() => assessments.Where(a => a.DisasterId == disasterId))); }
public async Task DeleteShelter(string shelterId) { var context = PersistenceContextFactory.CreateFor <Shelter>(); var shelters = await GetShelters(); foreach (var shelter in shelters.Where(s => shelterId == s.ObjectId)) { await Asyncer.Async(() => context.MarkDeleted(shelter)); } }
public async Task DeleteShelterAttribute(string attributeId) { var context = PersistenceContextFactory.CreateFor <ShelterAttribute>(); var shelterAttribute = context.LoadAll().SingleOrDefault(a => a.ObjectId == attributeId); if (shelterAttribute != null) { await Asyncer.Async(() => context.MarkDeleted(shelterAttribute)); } }
public async Task DeleteAssessments(string disasterId) { var context = PersistenceContextFactory.CreateFor <Assessment>(); var assessments = await GetAssessments(disasterId); foreach (var assessment in assessments) { await Asyncer.Async(() => context.MarkDeleted(assessment)); } }
public async Task DeleteShelters(string disasterId) { var context = PersistenceContextFactory.CreateFor <Shelter>(); var shelters = await GetShelters(disasterId); foreach (var shelter in shelters) { await Asyncer.Async(() => context.MarkDeleted(shelter)); } }
public async Task <UpdateResult <T> > Push <T>(string userToken, Predicate <T> criteria = null) where T : BaseModel { var headers = new Dictionary <string, string>(Connection.Headers) { { "user-token", userToken } }; criteria = criteria ?? (a => true); var context = PersistenceContextFactory.CreateFor <T>(); var items = await Asyncer.Async(() => context.LoadAll()); var result = new UpdateResult <T>(); foreach (var item in items.Where(i => criteria(i))) { var json = await PushItem(item, headers); var parsed = ResponseParser.Parse <T>(json); if (parsed.IsSuccessful) { var content = parsed.Content.Single(); context.Save(content); if (item.IsNew()) { context.Purge(item.ObjectId); } result.Success(content, item.ObjectId); } else { result.Failed(item, parsed.ToString()); } } return(result); }
public Task <Assessment> GetAssessment(string disasterId, string assessmentId) { var context = PersistenceContextFactory.CreateFor <Assessment>(); return(Asyncer.Async(() => context.LoadAll().SingleOrDefault(a => a.DisasterId == disasterId && a.ObjectId == assessmentId))); }
public Task <IEnumerable <Assessment> > GetAssessments() { var context = PersistenceContextFactory.CreateFor <Assessment>(); return(Asyncer.Async(context.LoadAll)); }
public Task DeleteAssessmentAttribute(string attributeId) { return(Asyncer.Async(() => _assessmentAttributes.Remove(attributeId))); }
public Task SaveAssessmentAttribute(AssessmentAttribute attribute) { return(Asyncer.Async(() => _assessmentAttributes[attribute.ObjectId] = attribute)); }
public Task SaveShelterAttribute(ShelterAttribute attribute) { return(Asyncer.Async(() => _shelterAttributes[attribute.ObjectId] = attribute)); }
public Task <IEnumerable <DisasterAid> > GetDisasterAids(string disasterId) { var context = _persistenceContextFactory.CreateFor <DisasterAid>(); return(Asyncer.Async(() => context.LoadAll().Where(d => d.DisasterId == disasterId))); }
public Task Save(Assessment assessment) { var context = PersistenceContextFactory.CreateFor <Assessment>(); return(Asyncer.Async(() => context.Save(assessment))); }
public Task <Shelter> GetShelter(string shelterId) { var context = PersistenceContextFactory.CreateFor <Shelter>(); return(Asyncer.Async(() => context.LoadAll().SingleOrDefault(s => s.ObjectId == shelterId))); }
public Task <IEnumerable <Shelter> > GetShelters() { var context = PersistenceContextFactory.CreateFor <Shelter>(); return(Asyncer.Async(context.LoadAll)); }
public Task DeleteShelterAttribute(string attributeId) { return(Asyncer.Async(() => _shelterAttributes.Remove(attributeId))); }
public async Task <IEnumerable <Shelter> > GetShelters(string disasterId) { var context = PersistenceContextFactory.CreateFor <Shelter>(); return(await Asyncer.Async(() => context.LoadAll().Where(s => s.DisasterId == disasterId))); }
public Task <IEnumerable <AssessmentAttribute> > GetAssessmentAttributes(string assessmentId) { var context = PersistenceContextFactory.CreateFor <AssessmentAttribute>(); return(Asyncer.Async(() => context.LoadAll().Where(d => d.ItemId == assessmentId))); }
public async Task <IEnumerable <Attribute> > GetAllAttributes() { var context = PersistenceContextFactory.CreateFor <Attribute>(); return(await Asyncer.Async(context.LoadAll)); }
public Task SaveAssessmentAttribute(AssessmentAttribute attribute) { var context = PersistenceContextFactory.CreateFor <AssessmentAttribute>(); return(Asyncer.Async(() => context.Save(attribute))); }
public Task Save(Shelter shelter) { var context = PersistenceContextFactory.CreateFor <Shelter>(); return(Asyncer.Async(() => context.Save(shelter))); }
public Task <IEnumerable <ShelterAttribute> > GetShelterAttributes(string shelterId) { var context = PersistenceContextFactory.CreateFor <ShelterAttribute>(); return(Asyncer.Async(() => context.LoadAll().Where(d => d.ItemId == shelterId))); }
public Task SaveShelterAttribute(ShelterAttribute attribute) { var context = PersistenceContextFactory.CreateFor <ShelterAttribute>(); return(Asyncer.Async(() => context.Save(attribute))); }
public Task Save(Assessment assessment) { return(Asyncer.Async(() => _assessments[assessment.ObjectId] = assessment)); }