Example #1
0
        /// <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);
                }
            }
        }
Example #2
0
 /// <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));
     }
 }
Example #3
0
 /// <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));
     }
 }
Example #4
0
 /// <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);
     }
 }
Example #5
0
 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));
     }
 }
Example #6
0
 public TInterface Create <TInterface>()
 {
     return(_block.Get <TInterface>());
 }