public async Task <TransactionResult> ReadProjects(TransactionCriteria criteria)
        {
            try
            {
                var result = new List <ProjectDTO>();
                if (criteria.Id != null)
                {
                    var s = await context.Project.FindAsync(criteria.Id);

                    result.Add(new ProjectDTO
                    {
                        Id               = s.Id,
                        Description      = s.Description,
                        UserFK           = s.UserFK,
                        Title            = s.Title,
                        ShortDescription = s.ShortDescription,
                        Goal             = s.Goal,
                        GoalMin          = s.GoalMin,
                        MainPhotoFK      = s.MainPhotoFK,
                        Video            = s.Video,
                        CategoryFK       = s.CategoryFK,
                        CategoryDesc     = s.ProjectCategory != null ? s.ProjectCategory.Description : null,
                        CategoryName     = s.ProjectCategory != null ? s.ProjectCategory.Title : null,
                        DueDate          = s.DueDate,
                        IsActive         = s.IsActive,
                        CreatedDate      = s.CreatedDate,
                        UpdatedDate      = s.UpdatedDate,
                        DeletedDate      = s.DeletedDate,
                        BlockedDate      = s.BlockedDate,
                        StateFK          = s.StateFK,
                        Website          = s.Website,
                        Gathered         = s.Gathered,
                        BackerCount      = s.BackerCount
                    });
                    return(new TransactionResult(TransResult.Success, string.Empty, result));
                }
                var res = context.Project.AsQueryable();
                res = res.Where(a => a.IsActive == true);
                if (criteria.UserId != null)
                {
                    res = res.Where(s => s.UserFK == criteria.UserId);
                }
                if (criteria.StateId != null)
                {
                    res = res.Where(s => s.StateFK == criteria.StateId);
                }
                if (criteria.CategoryId != null)
                {
                    res = res.Where(s => s.CategoryFK == criteria.CategoryId);
                }
                if (criteria.Search != null && criteria.Search != "")
                {
                    res = res.Where(s => s.Title.Contains(criteria.Search) || s.ShortDescription.Contains(criteria.Search));
                }
                if (criteria.Page != null)
                {
                    res = res.OrderBy(s => s.Id).Skip((int)criteria.Page * 6).Take(6);
                }
                if (criteria.NewestProject != null)
                {
                    if (criteria.NewestProject == 0)
                    {
                        criteria.NewestProject = 6;
                    }
                    res = res.OrderByDescending(s => s.CreatedDate).Take((int)criteria.NewestProject);
                }
                if (criteria.TrendingProjects != null)
                {
                    if (criteria.AfterDate == null)
                    {
                        criteria.AfterDate = DateTime.Now.AddDays(-7);
                    }

                    res = res.Where(x => (
                                        from p in context.Payment
                                        where (((DateTime)criteria.AfterDate).CompareTo(p.PaymentDate) <= 0 && (p.Amount - p.RefundedAmount != 0))
                                        group p by p.ProjectFK into ProjectIDs
                                        let countPayments = ProjectIDs.Count()
                                                            orderby countPayments descending
                                                            select ProjectIDs.Key).Take((int)criteria.TrendingProjects).Contains(x.Id));
                }

                result = await res.Select(s => new ProjectDTO
                {
                    Id               = s.Id,
                    Description      = s.Description,
                    UserFK           = s.UserFK,
                    Title            = s.Title,
                    ShortDescription = s.ShortDescription,
                    Goal             = s.Goal,
                    GoalMin          = s.GoalMin,
                    MainPhotoFK      = s.MainPhotoFK,
                    Video            = s.Video,
                    CategoryFK       = s.CategoryFK,
                    CategoryDesc     = s.ProjectCategory != null ? s.ProjectCategory.Description : null,
                    CategoryName     = s.ProjectCategory != null ? s.ProjectCategory.Title : null,
                    DueDate          = s.DueDate,
                    IsActive         = s.IsActive,
                    CreatedDate      = s.CreatedDate,
                    UpdatedDate      = s.UpdatedDate,
                    DeletedDate      = s.DeletedDate,
                    BlockedDate      = s.BlockedDate,
                    StateFK          = s.StateFK,
                    Website          = s.Website,
                    Gathered         = s.Gathered,
                    BackerCount      = s.BackerCount
                }).ToListAsync(); // Query Execute __________________________________

                return(new TransactionResult(TransResult.Success, string.Empty, result));
            }
            catch (Exception ex) { return(new TransactionResult(TransResult.Fail, ex.Message, ex)); }
        }
        public async Task <TransactionResult> ReadPayments(TransactionCriteria criteria)
        {
            try
            {
                var result = new List <PaymentDTO>();

                // Checking if an Id, ProjectId or UserId has been given
                // so that it will not return all payments.
                if (criteria.Id == null &&
                    criteria.ProjectId == null &&
                    (criteria.UserId == "" || criteria.UserId == null))
                {
                    return(new TransactionResult(TransResult.Fail, string.Empty, null));
                }

                if (criteria.Id != null)
                {
                    var s = await context.Payment.FindAsync(criteria.Id);

                    result.Add(new PaymentDTO
                    {
                        Id              = s.Id,
                        ProjectFK       = s.ProjectFK,
                        UserFK          = s.UserFK,
                        Amount          = s.Amount,
                        Rewards         = s.Rewards,
                        PaymentDate     = s.PaymentDate,
                        PaymentMethod   = s.PaymentMethod,
                        RefundedAmount  = s.RefundedAmount,
                        RefundedDate    = s.RefundedDate,
                        ProjectTitle    = s.Project != null ? s.Project.Title : null,
                        ProjectGathered = s.Project != null ? s.Project.Gathered : 0,
                        ProjectGoal     = s.Project != null ? s.Project.Goal : 0,
                        TransactionId   = s.TransactionId
                    });
                    return(new TransactionResult(TransResult.Success, string.Empty, result));
                }
                var res = context.Payment.AsQueryable();
                if (criteria.ProjectId != null)
                {
                    res = res.Where(s => s.ProjectFK == criteria.ProjectId);
                }
                if (criteria.UserId != null)
                {
                    res = res.Where(s => s.UserFK == criteria.UserId);
                }
                if (criteria.Page != null)
                {
                    res = res.OrderBy(s => s.Id).Skip((int)criteria.Page * 3).Take(3);
                }
                result = res.Select(s => new PaymentDTO
                {
                    Id              = s.Id,
                    ProjectFK       = s.ProjectFK,
                    UserFK          = s.UserFK,
                    Amount          = s.Amount,
                    Rewards         = s.Rewards,
                    PaymentDate     = s.PaymentDate,
                    PaymentMethod   = s.PaymentMethod,
                    RefundedAmount  = s.RefundedAmount,
                    RefundedDate    = s.RefundedDate,
                    ProjectTitle    = s.Project != null ? s.Project.Title : null,
                    ProjectGathered = s.Project != null ? s.Project.Gathered : 0,
                    ProjectGoal     = s.Project != null ? s.Project.Goal : 0,
                    TransactionId   = s.TransactionId
                }).ToList(); // Query Execute __________________________________
                return(new TransactionResult(TransResult.Success, string.Empty, result));
            }
            catch (Exception ex) { return(new TransactionResult(TransResult.Fail, ex.Message, ex)); }
        }