public async Task <int> SaveAsync(ISQLiteDataItem dataItem) { Type type = dataItem.GetType(); if (type == typeof(Client)) { if (dataItem.Id == 0) { dataItem.Id = NextId_Client++; } Clients[dataItem.Id] = (Client)dataItem; } else if (type == typeof(Project)) { if (dataItem.Id == 0) { dataItem.Id = NextId_Project++; } Projects[dataItem.Id] = (Project)dataItem; } else if (type == typeof(Workshift)) { if (dataItem.Id == 0) { dataItem.Id = NextId_Workshift++; } Workshifts[dataItem.Id] = (Workshift)dataItem; } return(await Task.FromResult(dataItem.Id).ConfigureAwait(false)); }
public DataItem(ISQLiteDataItem obj) { if (!(obj is DataItem item)) { throw new ArgumentException("Object passed to ISQLiteDataItem was for cloning was not a derived class of ISQLiteDataItem."); } Id = item.Id; Name = item.Name; Description = item.Description; }
/// <summary> /// Inserts the item if it is a new item, updates it if it already exists in the database. /// </summary> /// <param name="item">SQLiteDatam item to save to database</param> /// <returns>Primary Key Id of saved item</returns> public async Task <int> SaveAsync(ISQLiteDataItem item) => item.Id != 0 ? await conn.UpdateAsync(item) : await conn.InsertAsync(item).ConfigureAwait(false);