public PackageFund CreatePackageFund(PackageFundOption fundOption) { PackageFund fund = new PackageFund { Backer = db.Backers.Find(fundOption.BackerId), Package = db.Packages.Find(fundOption.PackageId), Project = db.Projects.Find(fundOption.ProjectId), DateFund = DateTime.Now }; Project project = db.Projects.Find(fundOption.ProjectId); project.CurrentAmount += fund.Package.Amount; project.NumberOfBackers += 1; if (project.CurrentAmount >= project.Goal) { project.State = false; } ProjectManagement prjMng = new ProjectManagement(db); project.Progress = prjMng.TrackProgressByProjectId(fundOption.ProjectId); db.Projects.Update(project); db.PackageFunds.Add(fund); db.SaveChanges(); PackageManagement pckMng = new PackageManagement(db); UserManagement userMng = new UserManagement(db); Backer backer = db.Backers.Find(fundOption.BackerId); backer.ProjectFunded = pckMng.FindProjectsFundedByBacker(fundOption.BackerId).Count; backer.TotalAmount = userMng.BackerTotalAmountSpent(fundOption.BackerId); db.Backers.Update(backer); db.SaveChanges(); return(fund); }
public ProjectStatus CreateProjectStatus(ProjectStatusOption psOption) { Project project = db.Projects.Find(psOption.ProjectId); ProjectStatus ps = new ProjectStatus { Title = psOption.Title, Project = project, Date = DateTime.Now }; db.ProjectStatuses.Add(ps); db.SaveChanges(); return(ps); }
//CRUD // create read update delete public Project CreateProject(ProjectOption projOption) { UserManagement pcMng = new UserManagement(db); Project project = new Project { ProjectCreator = pcMng.FindProjectCreatorById(projOption.ProjectCreatorId), Title = projOption.Title, Description = projOption.Description, Category = projOption.Category, EndDate = projOption.EndDate, Goal = projOption.Goal, ThemeImage = projOption.ThemeImage, Progress = 0, StartDate = DateTime.Now, State = true, CurrentAmount = 0, NumberOfBackers = 0 }; db.Projects.Add(project); db.SaveChanges(); return(project); }
public Media CreateMedia(MediaOption mediaOption) { Project project = db.Projects.Find(mediaOption.ProjectId); Media media = new Media { Type = mediaOption.Type, URL = mediaOption.URL, Project = project }; db.Medias.Add(media); db.SaveChanges(); return(media); }
public Backer CreateBacker(UserOption backOption) { Backer backer = new Backer { FirstName = backOption.FirstName, LastName = backOption.LastName, Email = backOption.Email, Username = backOption.Username, Password = backOption.Password, Dob = backOption.Dob, Role = backOption.Role, TotalAmount = 0, ProjectFunded = 0, }; db.Backers.Add(backer); db.SaveChanges(); return(backer); }