protected void Page_Load(object sender, EventArgs e) { //to avoid duplication in dropdown lists if (IsPostBack) { detailaction2_sender.DataSourceID = ""; Items.Clear(); } if (Request.Cookies["user"] != null) { string decoded_username = Encoding.UTF8.GetString(MachineKey.Unprotect(Convert.FromBase64String(Request.Cookies["user"]["username"]), "ProtectCookieUsername")); string decoded_role = Encoding.UTF8.GetString(MachineKey.Unprotect(Convert.FromBase64String(Request.Cookies["user"]["role"]), "ProtectCookieRole")); person_id = Convert.ToInt32(Encoding.UTF8.GetString(MachineKey.Unprotect(Convert.FromBase64String(Request.Cookies["user"]["person"]), "ProtectCookiePerson"))); case_id = Convert.ToInt32(Request.QueryString["case_id"]); if (decoded_role == "admin" || decoded_role == "support") { } else { Response.Redirect("~/"); } } else { Response.Redirect("~/"); } if (!String.IsNullOrEmpty(Request.QueryString["id"])) { id = Convert.ToInt32(Request.QueryString["id"]); } int isNew = Convert.ToInt32(Request.QueryString["new"]); if (!IsPostBack) { SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(SiteMap_SiteMapResolve); if (isNew == 1) { action_model action = new action_model() { dt = DateTime.Now, incident = case_id, description = "default" }; Support s = new Support(); s.Actions.Add(action); s.SaveChanges(); id = action.id; detailaction2_date.Text = action.dt.ToString("MM/dd/yyyy"); Support support = new Support(); var p_query = from p in support.Incidents where p.id == action.incident select p; detailaction2_case.Text = p_query.FirstOrDefault().description; } else { try { Support support = new Support(); Support personnel = new Support(); var action = from a in support.Actions where a.id == id select new { a.incident, a.receiver, a.sender, a.description, a.dt }; //date if (action.FirstOrDefault().dt != null) { detailaction2_date.Text = action.FirstOrDefault().dt.ToString("MM/dd/yyyy"); } else { detailaction2_date.Text = "No date..."; } //description if (String.IsNullOrEmpty(action.FirstOrDefault().description) || action.FirstOrDefault().description == "default") { detailaction2_desc.Text = ""; } else { desc = action.FirstOrDefault().description.ToString(); detailaction2_desc.Text = desc; } //case List<int> all_cases = (from x in support.Incidents select x.id).ToList(); if (!all_cases.Contains(Convert.ToInt32(action.FirstOrDefault().incident.ToString()))) { detailaction2_case.Text = "No case..."; } else { var p_query = from p in support.Incidents where p.id == action.FirstOrDefault().incident select p; detailaction2_case.Text = p_query.FirstOrDefault().description; } //sender List<int> all_members = (from x in personnel.members select x.id).ToList(); if (!all_members.Contains(Convert.ToInt32(action.FirstOrDefault().sender.ToString()))) { detailaction2_sender.SelectedValue = ""; } else { int s = Convert.ToInt32(action.FirstOrDefault().sender.ToString()); detailaction2_sender.SelectedValue = action.FirstOrDefault().sender.ToString(); } //receiver if (!String.IsNullOrEmpty(action.FirstOrDefault().receiver)) { detailaction2_receiver.Text = action.FirstOrDefault().receiver.ToString(); } else { // detailaction2_desc.Text = desc; } ////receiver //if (!all_members.Contains(Convert.ToInt32(action.FirstOrDefault().receiver.ToString()))) //{ // detailaction2_receiver.Text = "No receiver..."; //} //else //{ // int s = Convert.ToInt32(action.FirstOrDefault().receiver.ToString()); // var rename = from r in personnel.people // join m in personnel.members // on r.id equals m.person // where m.id == s // select r; // detailaction2_receiver.Text = rename.FirstOrDefault().lastname + " " + rename.FirstOrDefault().firstname; //} } catch (Exception ex) { Response.Write(ex); } } } detailaction2_sender.AppendDataBoundItems = true; }
//submit protected void Unnamed3_Click(object sender, EventArgs e) { try { action_model action = new action_model() { dt = DateTime.Now, incident = case_id, description = detailaction_desc.Text, }; if (detailaction_receiver.SelectedValue != "") { action.sender = Convert.ToInt32(detailaction_sender.SelectedValue.ToString()); } //if (detailaction_receiver.SelectedValue != "") //{ // action.receiver = Convert.ToInt32(detailaction_receiver.SelectedValue.ToString()); //} Support s = new Support(); s.Actions.Add(action); s.SaveChanges(); Response.Redirect(prevPage); } catch (System.Exception ex) { Response.Write(ex); } }