public void ProjectChecklistsOnUpdateCreate(int?ProjectId, List <ProjectServiceENT> ServicesList) { NbkDbEntities db = new NbkDbEntities(); List <int> ProjectServiceIDs = ServicesList.Select(X => X.Id).ToList(); //var list = (from r in db.ProjectChecklist where r.ProjectId == ProjectId select r).ToList(); if (ProjectId != null) { var listServices = ListOfProjectServicesForUpdate(Convert.ToInt32(ProjectId), ProjectServiceIDs); foreach (var item in listServices) { ChecklistTemplate ObjChecklistTemp = ChecklistTempByServiceID(item.ServiceId); Service ObjService = ServiceByServiceID(item.ServiceId); int totalServices = Convert.ToInt32(item.Quantity); //int a = i + 1; if (totalServices > 0) { for (int i = 0; i < totalServices; i++) { //Checklist for ServiceNameHere ProjectChecklist obj = new ProjectChecklist(); obj.ProjectId = item.ProjectId; if (item.Service.ChecklistTempId != null) { obj.ChecklistName = ObjChecklistTemp.Title; } else { obj.ChecklistName = "Checklist for " + ObjService.Name; } db.ProjectChecklist.Add(obj); db.SaveChanges(); if (ObjService.ChecklistTempId != null) { int ProjectChecklistID = obj.Id; int ChecklistTempId = Convert.ToInt32(ObjService.ChecklistTempId); SaveChecklistTemp(ChecklistTempId, ProjectChecklistID); } } } else { ProjectChecklist obj = new ProjectChecklist(); obj.ProjectId = item.ProjectId; obj.SortOrder = item.Id; obj.ChecklistName = item.Service.Name + " Checklist"; db.ProjectChecklist.Add(obj); db.SaveChanges(); } //Service status change var ProService = db.ProjectService.Where(x => x.Id == item.Id).FirstOrDefault(); ProService.IsNewAdded = false; db.SaveChanges(); } } }
public void ProjectChecklistsCreate(int?ProjectId) { NbkDbEntities db = new NbkDbEntities(); //var list = (from r in db.ProjectChecklist where r.ProjectId == ProjectId select r).ToList(); if (ProjectId != null) { var listServices = ListOfProjectServices(Convert.ToInt32(ProjectId)); foreach (var item in listServices) { ChecklistTemplate ObjChecklistTemp = ChecklistTempByServiceID(item.ServiceId); Service ObjService = ServiceByServiceID(item.ServiceId); int totalServices = Convert.ToInt32(item.Quantity); //int a = i + 1; if (totalServices > 0) { for (int i = 0; i < totalServices; i++) { //Checklist for ServiceNameHere ProjectChecklist obj = new ProjectChecklist(); obj.ProjectId = item.ProjectId; if (ObjChecklistTemp != null && !string.IsNullOrEmpty(ObjChecklistTemp.Title)) { obj.ChecklistName = ObjChecklistTemp.Title; } else { obj.ChecklistName = "Checklist for " + ObjService.Name; } db.ProjectChecklist.Add(obj); db.SaveChanges(); if (ObjService.ChecklistTempId != null) { if (ObjService.ChecklistTempId > 0) { int ProjectChecklistID = obj.Id; if (ObjChecklistTemp != null) { int ChecklistTempId = Convert.ToInt32(ObjService.ChecklistTempId); SaveChecklistTemp(ChecklistTempId, ProjectChecklistID); } } } } } else { ProjectChecklist obj = new ProjectChecklist(); obj.ProjectId = item.ProjectId; obj.SortOrder = item.Id; obj.ChecklistName = item.Service.Name + " Checklist"; db.ProjectChecklist.Add(obj); db.SaveChanges(); } //Service status change var ProService = db.ProjectService.Where(x => x.Id == item.Id).FirstOrDefault(); ProService.IsNewAdded = false; db.SaveChanges(); } } //if (list.Count != 0) //{ // //Service added new into project // var listServices = new ProjectServicesModel().ListOfProjectServicesAddedNew(Convert.ToInt32(id)); // foreach (var item in listServices) // { // int totalServices = Convert.ToInt32(item.Quantity); // //int a = i + 1; // if (totalServices > 0) // { // for (int i = 0; i < totalServices; i++) // { // //Checklist for ServiceNameHere // ProjectChecklist obj = new ProjectChecklist(); // obj.ProjectId = item.ProjectID; // obj.SortOrder = item.ID; // if (item.Service.ChecklistTempID != null) // { // obj.ChecklistName = item.Service.ChecklistTemplate.Title; // } // else // { // obj.ChecklistName = "Checklist for " + item.Service.Name; // } // db.ProjectChecklists.Add(obj); // db.SaveChanges(); // if (item.Service.ChecklistTempID != null) // { // int cheklistIdP = obj.Id; // int ChecklistTempId = Convert.ToInt32(item.Service.ChecklistTempID); // new NBKProject.Controllers.ChecklistController().SaveChecklistTemp(ChecklistTempId, cheklistIdP); // } // } // } // else // { // ProjectChecklist obj = new ProjectChecklist(); // obj.ProjectId = item.ProjectID; // obj.SortOrder = item.ID; // obj.ChecklistName = item.Service.Name + " Checklist"; // // db.ProjectChecklists.Add(obj); // // db.SaveChanges(); // } // //Service status change // // var ProService = db.ProjectServices.Where(x => x.ID == item.ID).FirstOrDefault(); // // ProService.IsNewAdded = false; // // db.SaveChanges(); // } // //End service added new code // //list = (from r in db.ProjectChecklists where r.ProjectId == id select r).ToList(); //} }