public object applyToProject(int projectId, String applyingLetter, double price, DateTime startDate, DateTime endDate) { int userId = (int)Session["id"]; var data = (from proj in db.ProjectTable // query to get the project status before apply where proj.ID == projectId select new { proj.status }).ToArray(); if ((int)data[0].status == 0) // if project isn't assigned to anyone yet (Waiting) { ApplyProject apply = new ApplyProject(); apply.applyingLetter = applyingLetter; apply.endDate = endDate; apply.price = price; apply.project = db.ProjectTable.Find(projectId); apply.projectManager = db.userTable.Find(userId); apply.startDate = startDate; db.ApplyProjectTable.Add(apply); db.SaveChanges(); return(JsonConvert.SerializeObject(new { operation = true })); } else { return(JsonConvert.SerializeObject(new { operation = false })); } }
public void declineApplyer(int PM_ID, int projectID) { User pm = db.userTable.Find(PM_ID); Project proj = db.ProjectTable.Find(projectID); ApplyProject applier = proj.applied.First(x => x.projectManager == pm); db.ApplyProjectTable.Remove(applier); db.SaveChanges(); }
public void Customer_assignProjectToPM(int PM_ID, int projectID) { User pm = db.userTable.Find(PM_ID); Project proj = db.ProjectTable.Find(projectID); ApplyProject applier = proj.applied.First(x => x.projectManager == pm); proj.projectManager = pm; proj.price = applier.price; proj.startDate = applier.startDate; proj.endDate = applier.endDate; proj.status = (status)1; var appliers = proj.applied.Where(x => x.project.ID == proj.ID); db.ApplyProjectTable.RemoveRange(appliers); //proj.applied.Clear(); db.SaveChanges(); }