public bool StatusUpdate(int backProjId, bool accept = false)
        {
            if (accept)
            {
                BackerProject backerProject = _db.BackerProjects
                                              .Include(bp => bp.Project)
                                              .Include(bp => bp.Backer)
                                              .Where(bp => bp.Id == backProjId)
                                              .FirstOrDefault();

                if (backerProject != null)
                {
                    Project project           = _db.Projects.Find(backerProject.ProjectId);
                    float   sumbackerprojects = _db.BackerProjects
                                                .Where(bp => bp.ProjectId == backerProject.ProjectId)
                                                .Where(bp => bp.Status == Status.Accepted)
                                                .Sum(bp => bp.Fund);

                    if (sumbackerprojects < project.BudgetGoal)
                    {
                        backerProject.Status           = Status.Accepted;
                        _db.Entry(backerProject).State = EntityState.Modified;
                        _db.SaveChanges();
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 2
0
        public bool UpdateBalance(int projectId)
        {
            Project project           = db.Projects.Find(projectId);
            float   sumbackerprojects = db.BackerProjects
                                        .Where(bp => bp.ProjectId == projectId)
                                        .Where(bp => bp.Status == Status.Accepted)
                                        .Sum(bp => bp.Fund);

            if (sumbackerprojects > 0)
            {
                project.Balance         = sumbackerprojects;
                db.Entry(project).State = EntityState.Modified;
                db.SaveChanges();
                return(true);
            }
            return(false);
        }