public bool AddFactoid(string user, string item, bool isAre, string value, bool replaceExisting) { if (replaceExisting) { ForgetFactoid(user, item); } var newFactoid = new Factoid() { User = user, Item = item, IsAre = isAre, Value = value, Timestamp = DateTime.UtcNow, }; _Db.Factoid.Add(newFactoid); var history = new FactoidHistory() { Item = item, Value = value, User = user, Timestamp = DateTime.UtcNow }; _Db.FactoidHistory.Add(history); _Db.SaveChanges(); return(true); }
public bool ForgetFactoid(string user, string item) { var existingFactoids = _Db.Factoid.Where(f => f.Item == item); if (!existingFactoids.Any()) { return(true); } var isLocked = existingFactoids.Any(f => f.IsLocked); if (isLocked) { return(false); } _Db.Factoid.RemoveRange(existingFactoids); var deleteHistory = new FactoidHistory() { Item = item, Value = null, User = user, Timestamp = DateTime.UtcNow }; _Db.FactoidHistory.Add(deleteHistory); _Db.SaveChanges(); return(true); }