Esempio n. 1
0
        /// <summary>
        /// Deletes the item from the DbContext
        /// </summary>
        /// <param name="item">the item to delete</param>
        public RepositoryResult Delete(T item, bool throwException = true)
        {
            var result = new RepositoryResult();

            try
            {
                var set      = _ctx.Set <T>();
                var existing = set.Attach(item);
                var r        = set.Attach(item);
                if (existing != null)
                {
                    _ctx.Set <T>().Remove(item);
                }

                if (Autosave)
                {
                    _ctx.SaveChanges();
                }
                result.NoErrors = true;
            }
            catch (Exception ex)
            {
                // LogError(ex);

                if (throwException)
                {
                    throw ex;
                }

                result.Message  = ex.GetBaseException().Message;
                result.NoErrors = false;
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Attaches and updates the item in the DbContext
        /// </summary>
        /// <param name="item">the item to update</param>
        public RepositoryResult Update(T item, bool throwException = true)
        {
            var result = new RepositoryResult();

            try
            {
                var set = _ctx.Set <T>();
                set.Attach(item);
                _ctx.Entry <T>(item).State = EntityState.Modified;
                if (Autosave)
                {
                    _ctx.SaveChanges();
                }
                result.NoErrors = true;
            }
            catch (Exception ex)
            {
                // LogError(ex);

                if (throwException)
                {
                    throw ex;//new RepositoryException(ex.Message, ex);
                }

                result.Message  = ex.GetBaseException().Message;
                result.NoErrors = false;
            }

            return(result);
        }
Esempio n. 3
0
 public RepositoryResultSingle(RepositoryResult repositoryResult)
 {
     this.Message  = repositoryResult.Message;
     this.NoErrors = repositoryResult.NoErrors;
 }