public T Add(T entity) { try { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } Entities.Add(entity); _context.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { _errorMessage += $"Error {validationError.ErrorMessage} in Property {validationError.PropertyName}" + Environment.NewLine; } } throw new Exception(_errorMessage, dbEx); } return(entity); }
public void Save() { _context.SaveChanges(); }