public Result InsertEntity <T>(T item, bool ignoreValidation = false) where T : class { using (DBContext context = new HotelReservationsContext()) { if (ContainsEntity(item, context)) { return(new Result(ResultType.ALREADY_IN_DATABASE)); } // validate item if needed if (!ignoreValidation) { Result result = Validate(item); if (result.type != ResultType.SUCCESS) { return(result); } } // add item context.Add(item); context.SaveChanges(); OnDBChange?.Invoke(context, typeof(T)); } return(new Result(ResultType.SUCCESS)); }
public void RemoveEntity <T>(T entity) { using (DBContext context = new HotelReservationsContext()) { context.Remove(entity); context.SaveChanges(); OnDBChange?.Invoke(context, typeof(T)); } }
public Result EditEntity <T>(T entity) where T : class { using (DBContext context = new HotelReservationsContext()) { if (!ContainsEntity(entity, context)) { return(new Result(ResultType.NOT_IN_DATABASE)); } Result result = Validate(entity); if (result.type != ResultType.SUCCESS) { return(result); } context.Update(entity); context.SaveChanges(); OnDBChange?.Invoke(context, typeof(T)); } return(new Result(ResultType.SUCCESS)); }