public override PagedData ProcessRequest(HttpContext context, CookDBDataContext db) { string user_name = context.Request.Params.Get("user_name"); if (isNull(user_name)) { return(new PagedData("CreateNewProject.ashx expects a user_name")); } ProjectInformation newProject = new ProjectInformation(); newProject.locked = true; //start the project off as locked by the user who created it newProject.user_name = user_name; // db.ProjectInformations.InsertOnSubmit(newProject); db.SubmitChanges(); //create the new project so we can have a new project_id with which to create new records in other tables //create a new record in dependent tables MISNew newMISNew = new MISNew(); newMISNew.project_id = newProject.project_id; db.MISNews.InsertOnSubmit(newMISNew); db.SubmitChanges(); MISNewDelivery newMISDelivery = new MISNewDelivery(); newMISDelivery.mis_new_id = newMISNew.mis_new_id; db.MISNewDeliveries.InsertOnSubmit(newMISDelivery); MISUpdate newMISUpdate = new MISUpdate(); newMISUpdate.project_id = newProject.project_id; newMISUpdate.description = ""; db.MISUpdates.InsertOnSubmit(newMISUpdate); db.SubmitChanges(); MISUpdateDeliveryChange newMISUpdateDeliveryChange = new MISUpdateDeliveryChange(); newMISUpdateDeliveryChange.mis_update_id = newMISUpdate.mis_update_id; db.MISUpdateDeliveryChanges.InsertOnSubmit(newMISUpdateDeliveryChange); ProdInstallationBuffet prodBuffet = new ProdInstallationBuffet(); prodBuffet.project_id = newProject.project_id; db.ProdInstallationBuffets.InsertOnSubmit(prodBuffet); PromptWorksheet promptWorksheet = new PromptWorksheet(); promptWorksheet.project_id = newProject.project_id; promptWorksheet.prompt_worksheet = ""; promptWorksheet.prompt_summary = ""; db.PromptWorksheets.InsertOnSubmit(promptWorksheet); SWDSchedule swdSchedule = new SWDSchedule(); swdSchedule.project_id = newProject.project_id; db.SWDSchedules.InsertOnSubmit(swdSchedule); TrafficRequirement trafficRequirement = new TrafficRequirement(); trafficRequirement.project_id = newProject.project_id; db.TrafficRequirements.InsertOnSubmit(trafficRequirement); UatProdInstall uatProdInstall = new UatProdInstall(); uatProdInstall.project_id = newProject.project_id; db.UatProdInstalls.InsertOnSubmit(uatProdInstall); db.SubmitChanges(); //insert a history note that the project was created ProjectHistory historyNote = new ProjectHistory(); historyNote.project_id = newProject.project_id; historyNote.user_name = user_name; historyNote.description = "Project created"; historyNote.date = DateTime.Today.ToString("yyyy-MM-dd"); db.ProjectHistories.InsertOnSubmit(historyNote); db.SubmitChanges(); return(new PagedData(new { newProject.project_id })); }
public override PagedData ProcessRequest(HttpContext context, CookDBDataContext db) { IQueryable <ProjectInformation> q = db.ProjectInformations; System.IO.StreamReader reader = new System.IO.StreamReader(context.Request.InputStream, context.Request.ContentEncoding); var jsonSerializer = new JsonSerializer(); JObject blob = (JObject)jsonSerializer.Deserialize(new JsonTextReader(new StringReader(reader.ReadToEnd()))); string filter = context.Request.Params.Get("project_id"); if (!isNull(filter)) { MISNew proj = db.MISNews.Single(a => a.project_id.Equals(int.Parse(filter))); int mis_new_id = proj.mis_new_id; //set newReportDescription panel if (((String)blob["newReportDescription"]) != null) { proj.description = (String)blob["newReportDescription"]; } //set File1 Reporting Info panel if (((String)blob["misNewBusinessUnit"]) != null) { proj.business_units_id = (db.BusinessUnits.Single(a => a.name.Equals((String)blob["misNewBusinessUnit"])).business_units_id); } else { proj.business_units_id = null; } if (((String)blob["misNewApplicationGroup"]) != null) { proj.application_group = (String)blob["misNewApplicationGroup"]; } db.SubmitChanges(); //DISTRIBUTION CHANGE var records_to_delete = db.MISNewDistributions.Where(a => a.mis_new_id.Equals(mis_new_id)); db.MISNewDistributions.DeleteAllOnSubmit(records_to_delete); db.SubmitChanges(); if ((String)blob["misnewDistributionAddEmail"] != "") { String[] emails = ((String)blob["misnewDistributionAddEmail"]).Split(';'); foreach (string email in emails) { string real_email = email.Trim(); MISNewDistribution record = new MISNewDistribution(); record.mis_new_id = mis_new_id; record.add_or_delete = "add"; record.contact_id = (db.Contacts.Single(a => a.email1.Equals(real_email))).contact_id; db.MISNewDistributions.InsertOnSubmit(record); db.SubmitChanges(); } } if ((String)blob["misNewDistributionDeleteEmail"] != "") { String[] emails = ((String)blob["misNewDistributionDeleteEmail"]).Split(';'); foreach (string email in emails) { string real_email = email.Trim(); MISNewDistribution record = new MISNewDistribution(); record.mis_new_id = mis_new_id; record.add_or_delete = "delete"; record.contact_id = (db.Contacts.Single(a => a.email1.Equals(real_email))).contact_id; db.MISNewDistributions.InsertOnSubmit(record); db.SubmitChanges(); } } //DELIVERY CHANGES MISNewDelivery delivery_record = db.MISNewDeliveries.Single(a => a.mis_new_id.Equals(mis_new_id)); if (blob["misNewFormat"] != null) { string formats = ""; if (blob["misNewFormat"].Type.ToString().Equals("String")) { formats = (String)(blob["misNewFormat"]); } else { if ((blob["misNewFormat"]).Count() != 0) { formats = (String)(blob["misNewFormat"][0]); for (int i = 1; i < ((JArray)blob["misNewFormat"]).Count; i++) { formats = formats + ", " + (String)(blob["misNewFormat"][i]); } } else { formats = ""; } } delivery_record.format = formats; } else { delivery_record.format = ""; } if (blob["misNewFrequency"] != null) { string frequencies = ""; if (blob["misNewFrequency"].Count() != 0) { frequencies = (String)(blob["misNewFrequency"][0]); for (int i = 1; i < ((JArray)blob["misNewFrequency"]).Count; i++) { frequencies = frequencies + ", " + (String)(blob["misNewFrequency"][i]); } } delivery_record.frequency = frequencies; } else { delivery_record.frequency = ""; } if (blob["misNewMethod"] != null) { string methods = ""; if (blob["misNewMethod"].Count() != 0) { methods = (String)(blob["misNewMethod"][0]); for (int i = 1; i < ((JArray)blob["misNewMethod"]).Count; i++) { methods = methods + ", " + (String)(blob["misNewMethod"][i]); } } delivery_record.method = methods; } else { delivery_record.method = ""; } db.SubmitChanges(); //REPORT NAMES var report_records = db.MISNewReportNames.Where(a => a.mis_new_id.Equals(mis_new_id)); db.MISNewReportNames.DeleteAllOnSubmit(report_records); if (blob["misNewRequestedReportName"] != null) { if (blob["misNewRequestedReportName"].GetType() == typeof(JValue)) { string[] reports = ((String)blob["misNewRequestedReportName"]).Split(','); foreach (string report in reports) { string real_report = report.Trim(); MISNewReportName record = new MISNewReportName(); record.report_name = real_report; record.mis_new_id = mis_new_id; db.MISNewReportNames.InsertOnSubmit(record); } } else { JArray reports = (JArray)blob["misNewRequestedReportName"]; for (int i = 0; i < reports.Count; i++) { MISNewReportName record = new MISNewReportName(); record.report_name = ((String)(blob["misNewRequestedReportName"][i])).Trim(); record.mis_new_id = mis_new_id; db.MISNewReportNames.InsertOnSubmit(record); } } } db.SubmitChanges(); } return(new PagedData("success")); }