public override PagedData ProcessRequest(HttpContext context, CookDBDataContext db) { string project_id = context.Request.Params.Get("project_id"); if (!isNull(project_id)) { string username = context.Request.Params.Get("user_name"); string permission = context.Request.Params.Get("permission"); SystemsAssessment record = new SystemsAssessment(); record.project_id = int.Parse(project_id); record.Contact = db.Contacts.Single(a => a.name.Equals("Test Guy")); record.description = ""; record.billed_hours = ""; record.booked_hours = ""; record.target_start = ""; record.target_complete = ""; record.scheduled_start = ""; record.scheduled_complete = ""; record.actual_complete = ""; db.SystemsAssessments.InsertOnSubmit(record); db.SubmitChanges(); doChangeLogging(username, permission, project_id, db); return(new PagedData(new { record.systems_req_id, record.Contact.name })); } return(new PagedData("AddSystemsAssessment.ashx requires a project_id")); }
public override PagedData ProcessRequest(HttpContext context, CookDBDataContext db) { string project_id = context.Request.Params.Get("project_id"); if (!isNull(project_id)) { string assessment_id = context.Request.Params.Get("assessment_id"); string username = context.Request.Params.Get("user_name"); string permission = context.Request.Params.Get("permission"); if (!isNull(assessment_id)) { SystemsAssessment record = db.SystemsAssessments.Single(a => a.systems_req_id.Equals(assessment_id)); doChangeLogging(assessment_id, username, permission, project_id, db, record); db.SystemsAssessments.DeleteOnSubmit(record); db.SubmitChanges(); return(new PagedData("SystemsAssessment deleted")); } return(new PagedData("RemoveSystemsAssessment.ashx requires an assessment_id")); } return(new PagedData("RemoveSystemsAssessment.ashx requires a project_id")); }
public override PagedData ProcessRequest(HttpContext context, CookDBDataContext db) { IQueryable <SystemsAssessment> q = db.SystemsAssessments; string username = context.Request.Params.Get("user_name"); string filter = context.Request.Params.Get("project_id"); 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 readOnly = context.Request.Params.Get("read_only"); if (readOnly == "true" && context.Request.RequestType != "GET") { return(new PagedData("Read Only")); } switch (context.Request.RequestType) { case "GET": { if (!isNull(filter)) { q = q.Where(a => a.project_id == int.Parse(filter)); return(new PagedData(q.Select(a => new { a.systems_req_id, a.description, a.Contact.name, a.billed_hours, a.booked_hours, a.target_start, a.target_complete, a.scheduled_start, a.scheduled_complete, a.actual_complete }))); } else { return(new PagedData("GetSystemsAssessment expects a project_id")); } } case "POST": { if (blob["rows"].GetType() == typeof(JObject)) { JObject obj = (JObject)blob["rows"]; SystemsAssessment record = new SystemsAssessment(); record.project_id = int.Parse(filter); record.Contact = db.Contacts.Single(a => a.name.Equals("Test Guy")); record.Contact.name = "Test Guy"; record.description = ""; record.billed_hours = ""; record.booked_hours = ""; record.target_start = ""; record.target_complete = ""; record.scheduled_start = ""; record.scheduled_complete = ""; record.actual_complete = ""; db.SystemsAssessments.InsertOnSubmit(record); db.SubmitChanges(); //return new PagedData(record); q = q.Where(a => a.project_id == int.Parse(filter) && a.systems_req_id == record.systems_req_id); return(new PagedData(q.Select(a => new { a.systems_req_id, a.description, a.Contact.name, a.billed_hours, a.booked_hours, a.target_start, a.target_complete, a.scheduled_start, a.scheduled_complete, a.actual_complete }))); } else { JArray objs = (JArray)blob["rows"]; List <SystemsAssessment> list = new List <SystemsAssessment>(); for (int j = 0; j < objs.Count; j++) { SystemsAssessment record = new SystemsAssessment(); record.project_id = int.Parse(filter); record.Contact = db.Contacts.Single(a => a.name.Equals("Test Guy")); record.description = ""; record.billed_hours = ""; record.booked_hours = ""; record.target_start = ""; record.target_complete = ""; record.scheduled_start = ""; record.scheduled_complete = ""; record.actual_complete = ""; db.SystemsAssessments.InsertOnSubmit(record); db.SubmitChanges(); list.Add(record); } return(new PagedData(list)); } } case "PUT": { if (blob["rows"].GetType() == typeof(JObject)) { JObject obj = (JObject)blob["rows"]; SystemsAssessment record = db.SystemsAssessments.Single(a => a.systems_req_id.Equals((int)obj["systems_req_id"])); try { record.Contact = db.Contacts.Single(a => a.name.Equals((string)obj["name"])); } catch (Exception) { record.Contact = db.Contacts.Single(a => a.name.Equals("Test Guy")); } record.description = (string)obj["description"]; record.billed_hours = (string)obj["billed_hours"]; record.booked_hours = (string)obj["booked_hours"]; record.target_start = obj["target_start"].ToString().Contains("T00:00:00") ? convertToProperDate((string)obj["target_start"]) : ((string)obj["target_start"] == null ? "" : (string)obj["target_start"]); record.target_complete = obj["target_complete"].ToString().Contains("T00:00:00") ? convertToProperDate((string)obj["target_complete"]) : ((string)obj["target_complete"] == null ? "" : (string)obj["target_complete"]); record.scheduled_start = obj["scheduled_start"].ToString().Contains("T00:00:00") ? convertToProperDate((string)obj["scheduled_start"]) : ((string)obj["scheduled_start"] == null ? "" : (string)obj["scheduled_start"]); record.scheduled_complete = obj["scheduled_complete"].ToString().Contains("T00:00:00") ? convertToProperDate((string)obj["scheduled_complete"]) : ((string)obj["scheduled_complete"] == null ? "" : (string)obj["scheduled_complete"]); record.actual_complete = obj["actual_complete"].ToString().Contains("T00:00:00") ? convertToProperDate((string)obj["actual_complete"]) : ((string)obj["actual_complete"] == null ? "" : (string)obj["actual_complete"]); db.SubmitChanges(); //return new PagedData(record); q = q.Where(a => a.project_id == int.Parse(filter) && a.systems_req_id == record.systems_req_id); return(new PagedData(q.Select(a => new { a.systems_req_id, a.description, a.Contact.name, a.billed_hours, a.booked_hours, a.target_start, a.target_complete, a.scheduled_start, a.scheduled_complete, a.actual_complete }))); } else { JArray objs = (JArray)blob["rows"]; List <SystemsAssessment> list = new List <SystemsAssessment>(); for (int j = 0; j < objs.Count; j++) { SystemsAssessment record = db.SystemsAssessments.Single(a => a.systems_req_id.Equals((int)objs["systems_req_id"])); try { record.Contact = db.Contacts.Single(a => a.name.Equals((string)objs["name"])); } catch (Exception) { record.Contact = db.Contacts.Single(a => a.name.Equals("Test Guy")); } record.description = (string)objs["description"]; record.billed_hours = (string)objs["billed_hours"]; record.booked_hours = (string)objs["booked_hours"]; record.target_start = objs["target_start"].ToString().Contains("T00:00:00") ? convertToProperDate((string)objs["target_start"]) : ((string)objs["target_start"] == null ? "" : (string)objs["target_start"]); record.target_complete = objs["target_complete"].ToString().Contains("T00:00:00") ? convertToProperDate((string)objs["target_complete"]) : ((string)objs["target_complete"] == null ? "" : (string)objs["target_complete"]); record.scheduled_start = objs["scheduled_start"].ToString().Contains("T00:00:00") ? convertToProperDate((string)objs["scheduled_start"]) : ((string)objs["scheduled_start"] == null ? "" : (string)objs["scheduled_start"]); record.scheduled_complete = objs["scheduled_complete"].ToString().Contains("T00:00:00") ? convertToProperDate((string)objs["scheduled_complete"]) : ((string)objs["scheduled_complete"] == null ? "" : (string)objs["scheduled_complete"]); record.actual_complete = objs["actual_complete"].ToString().Contains("T00:00:00") ? convertToProperDate((string)objs["actual_complete"]) : ((string)objs["actual_complete"] == null ? "" : (string)objs["actual_complete"]); db.SubmitChanges(); list.Add(record); } return(new PagedData(list)); } } case "DELETE": { if (blob["rows"].GetType() == typeof(JObject)) { JObject obj = (JObject)blob["rows"]; SystemsAssessment record = db.SystemsAssessments.Single(a => a.systems_req_id.Equals((int)obj["systems_req_id"])); db.SystemsAssessments.DeleteOnSubmit(record); db.SubmitChanges(); return(new PagedData("SystemsAssessment Rec Deleted")); } else { JArray objs = (JArray)blob["rows"]; List <SystemsAssessment> list = new List <SystemsAssessment>(); for (int j = 0; j < objs.Count; j++) { JObject obj = (JObject)blob["rows"]; SystemsAssessment record = db.SystemsAssessments.Single(a => a.systems_req_id.Equals((int)obj["systems_req_id"])); db.SystemsAssessments.DeleteOnSubmit(record); db.SubmitChanges(); } return(new PagedData("SystemsAssessment Recs Deleted")); } } default: return(new PagedData("Error: Unsupported Http Request: " + context.Request.RequestType + " not recognized", false)); } }
public void doChangeLogging(string type, string username, string permission, string project_id, CookDBDataContext db, SystemsAssessment record) { //if (permission != "PM") //{ ChangeLog newLog = new ChangeLog(); newLog.project_id = Convert.ToInt32(project_id); newLog.time = DateTime.Now.ToShortTimeString(); newLog.date = DateTime.Now.ToShortDateString(); newLog.tab = "Systems"; newLog.user_name = username; string description = (record.description == null || record.description == "") ? "(empty)" : record.description; string billed = (record.billed_hours == null || record.billed_hours == "") ? "(empty)" : record.billed_hours; string booked = (record.booked_hours == null || record.booked_hours == "") ? "(empty)" : record.booked_hours; string targetstart = (record.target_start == null || record.target_start == "") ? "(empty)" : record.target_start; string targetcomplete = (record.target_complete == null || record.target_complete == "") ? "(empty)" : record.target_complete; string scheduledstart = (record.scheduled_start == null || record.scheduled_start == "") ? "(empty)" : record.scheduled_start; string scheduledcomplete = (record.scheduled_complete == null || record.scheduled_complete == "") ? "(empty)" : record.scheduled_complete; string actualcomplete = (record.actual_complete == null || record.actual_complete == "") ? "(empty)" : record.actual_complete; newLog.description = "Existing record deleted from Systems Engineering Assessment: Name: " + record.Contact.name + "; Description: " + description + "; Billed Hours: " + billed + "; Booked Hours: " + booked + "; Target Start: " + targetstart + "; Target Complete: " + targetcomplete + "; Scheduled Start: " + scheduledstart + "; Scheduled Complete: " + scheduledcomplete + "; Actual Complete: " + actualcomplete + "."; db.ChangeLogs.InsertOnSubmit(newLog); db.SubmitChanges(); //} }