/// <summary> /// Adds, updates or deletes the specific data from the server /// </summary> /// <param name="data">The data.</param> /// <returns>true if successful</returns> private bool AddUpdateDelete(BaseModel data, BaseModel currentData) { bool okay = true; try { data.Synced = true; var newObject = data.CastAs(Type.GetType(data.TypeDiscriptor)); if (newObject != null && currentData == null) { DataHandler.Insert(newObject); AssassinCache.AddOrUpdate(data); } else if (newObject != null && currentData != null && currentData.ModifiedDT < newObject.ModifiedDT) { if ((newObject as BaseModel).Archived) { DataHandler.Delete(newObject); AssassinCache.Remove(data); } else { DataHandler.Update(newObject); AssassinCache.AddOrUpdate(data); } } } catch (Exception ex) { OnNotify?.Invoke(this, ex.ToText("Error updating data received from server."), LogLevel.Error); okay = false; } return(okay); }
/// <summary> /// Gets specific items from the cache. /// </summary> /// <typeparam name="T"></typeparam> /// <returns>a list of the requested item</returns> public static List <T> Get <T>(int skip = 0, int load = 9999) where T : BaseModel { List <T> result = new List <T>(); var BaseModels = BaseModelsCache.Values.ToList().Where(p => p.TypeDiscriptor == typeof(T).AssemblyQualifiedName && !p.Archived).Skip(skip).Take(load); foreach (var BaseModel in BaseModels) { result.Add(BaseModel.CastAs <T>()); } return(result.OrderByDescending(p => p.CreatedDT).ToList()); }
/// <summary> /// Gets all. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="includeAll">if set to <c>true</c> [include all].</param> /// <returns></returns> internal async Task <IEnumerable <T> > GetAll <T>(bool includeAll) where T : BaseModel { try { List <T> result = new List <T>(); var BaseModels = await this.webservice.Fetch(typeof(T).AssemblyQualifiedName, null, includeAll); if (BaseModels.Count > 0) { foreach (var BaseModel in BaseModels) { result.Add(BaseModel.CastAs <T>()); } } return(result); } catch (Exception ex) { AssassinDataService.OnNotify?.Invoke(this, ex.ToText("Error fetching data from server - method GetAll failed."), LogLevel.Error); } return(null); }