示例#1
0
        /// <summary>
        /// This will delete an item from the database
        /// </summary>
        /// <param name="keys">The keys must be given in the same order as entity framework has them</param>
        /// <returns></returns>
        public ISuccessOrErrors Delete <TEntity>(params object[] keys) where TEntity : class
        {
            var entityToDelete = _db.Set <TEntity>().Find(keys);

            if (entityToDelete == null)
            {
                return
                    (new SuccessOrErrors().AddSingleError(
                         "Could not delete entry as it was not in the database. Could it have been deleted by someone else?"));
            }

            _db.Set <TEntity>().Remove(entityToDelete);
            var result = _db.SaveChangesWithChecking();

            if (result.IsValid)
            {
                result.SetSuccessMessage("Successfully deleted {0}.", typeof(TEntity).Name);
            }

            return(result);
        }