Exemplo n.º 1
0
        public void DeleteProject(int id)
        {
            Project        project           = freelanceContext.Projects.FirstOrDefault(x => x.Id == id);
            List <Offer>   offersOfProject   = freelanceContext.Offers.Where(x => x.ProjectId == project.Id).ToList();
            List <Payment> paymentsOfProject = paymentDal.getByProjectId(project.Id);

            foreach (Offer offer in offersOfProject)
            {
                freelanceContext.Offers.Remove(offer);
                freelanceContext.SaveChanges();
            }

            foreach (Payment payment in paymentsOfProject)
            {
                paymentDal.Delete(payment.Id);
            }

            freelanceContext.Projects.Remove(project);
            freelanceContext.SaveChanges();
        }