Exemple #1
0
        public IRepositoryOperationResult <T> GetById(object id)
        {
            IRepositoryOperationResult <T> result = null;

            try
            {
                var set = this.context.Set <T>();

                T entity = set.Find(new object[] { id });

                result = new RepositoryOperationResult <T>()
                {
                    Entity = entity,
                    Status = EOperationsStatus.Success
                };
            }
            catch (Exception ex)
            {
                result = new RepositoryOperationResult <T>()
                {
                    Entity    = null,
                    Status    = EOperationsStatus.Fail,
                    Exception = ex,
                    Message   = ex.Message
                };
            }

            return(result);
        }
Exemple #2
0
        public IRepositoryOperationResult <T> Delete(T entity)
        {
            IRepositoryOperationResult <T> result = null;

            try
            {
                var set = this.context.Set <T>();

                set.Remove(entity);

                result = new RepositoryOperationResult <T>()
                {
                    Entity = entity,
                    Status = EOperationsStatus.Success
                };
            }
            catch (Exception ex)
            {
                result = new RepositoryOperationResult <T>()
                {
                    Entity    = entity,
                    Status    = EOperationsStatus.Fail,
                    Exception = ex,
                    Message   = ex.Message
                };
            }

            return(result);
        }