예제 #1
0
        /// <summary>
        /// Deletes the specified item that contains the id.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="errors"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public bool TryDelete(int id, List <IModelError> errors, IModelContext context = null)
        {
            var exists = Exists(id, context);

            if (!exists)
            {
                AddNotExistsError(errors);
                return(false);
            }

            try
            {
                changeHandler.BeforeDelete(id, context);
                dal.Delete(id, context);
                changeHandler.AfterDelete(id, context);
            }
            catch (Exception ex)
            {
                log.Exception(LogName, ex);
                throw new InvalidOperationException("Unable to delete IRoleDataModel", ex);
            }

            return(true);
        }