protected DBCache GetDBCache() { var cache = new DBCache(); cache.Items = GetAllItems(); return cache; }
public AddUpdateResult AddOrUpdate(ItemsVM itemVm, int itemId, DBCache cache) { try { if (itemId > 0) { var existingItem = _Context.Items.Find(itemId); if (existingItem != null) { bool bChanged = existingItem.UpdateValues(itemVm); if (bChanged == false) return AddUpdateResult.NoChange; _Context.SaveChanges(); return AddUpdateResult.Updated; } return AddUpdateResult.Error; } var item = Items.CreateFromViewModel(itemVm); _Context.Items.Add(item); _Context.SaveChanges(); itemVm.Id = item.Id; return AddUpdateResult.Added; } catch (DbEntityValidationException e) { Log(LogLevel.Error, GetExceptionMessage(e)); throw; } catch (DbUpdateException e) { Log(LogLevel.Error, GetExceptionMessage(e)); throw; } }