/// <summary> /// Adds/Updates the data from in reposiotry and tells all (subscribing) clients about it. /// /// Override to implement custom logic /// </summary> /// <param name="model"></param> public virtual async Task Update(TM model) { var command = DataSyncCommand.Update; if (model.Id == 0) { command = DataSyncCommand.Add; } using (var block = new ActivationBlock(kernel)) { var s = block.Get <TS>(); //Send back the data in the repo for the type TV var result = s.SaveOrUpdate(model); if (result.IsValid) { //Ok, tell all clients about the update result.SetViewModel(); await Sync(command, result.EntityViewModel); } else { //Could not save, send information back to caller await this.Invoke(result, DataSyncCommand.Error); } } }
/// <summary> /// Search the repository, not exposed to clients since accessor is protected /// </summary> /// <param name="expression"></param> /// <returns></returns> protected virtual IEnumerable <TM> Find(Func <TM, bool> expression) { using (var block = new ActivationBlock(kernel)) { var s = block.Get <TS>(); //Send back the data in the repo for the type TV return(s.Find(expression)); } }
/// <summary> /// Will fetch and send all data in the repository for each topic sent in with the connection. /// </summary> public override async Task OnOpened() { using (var block = new ActivationBlock(kernel)) { var s = block.Get <TS>(); //Send back the data in the repo for the type TV await this.Invoke(s.GetAll(), string.Format("{0}:{1}", DataSyncCommand.Init, Entity)); } }
/// <summary> /// Deletes the data from the reposiotry and tells all (subscribing) clients about it /// /// Override to implement custom logic /// </summary> /// <param name="model"></param> public virtual async Task Delete(TVM model) { using (var block = new ActivationBlock(kernel)) { var s = block.Get <TS>(); s.Delete(model.Id); await Sync(DataSyncCommand.Delete, model); } }
public async Task Page(int page, int pageSize) { using (var block = new ActivationBlock(kernel)) { var s = block.Get <TS>(); var entities = new List <TVM>(); var p = s.Page(page, pageSize); foreach (var entity in p.Entities) { var vc = entity.GetValidationContainer(default(TVM)); vc.SetViewModel(); entities.Add(vc.EntityViewModel); } await this.Invoke(new Page <TVM>(entities, p.Count, p.PageSize, p.CurrentPage), string.Format("{0}:{1}", DataSyncCommand.Page, Entity)); } }
public TInterface Create <TInterface>() { return(_block.Get <TInterface>()); }