public static ReturnObject Delete(HttpContext context, long id) { if (id <= 0) return new ReturnObject() { Error = true, Message = "Invalid Question." }; var item = new Lib.Data.DSQ.Question(id); item.Delete(); return new ReturnObject() { Growl = new ReturnGrowlObject() { Type = "default", Vars = new ReturnGrowlVarsObject() { text = "You have successfully deleted a question.", title = "Question Deleted" } }, Actions = new List<ReturnActionObject>() { new ReturnActionObject() { Ele = "#questions-table tr[data-id=\""+id.ToString()+"\"]", Type = "remove" } } }; }
protected void Page_Init(object sender, EventArgs e) { string strID = Request.QueryString["id"]; long id; if (string.IsNullOrEmpty(strID) || !long.TryParse(strID, out id)) item = new Lib.Data.DSQ.Question(); else item = new Lib.Data.DSQ.Question(id); }
public static ReturnObject Edit( HttpContext context, long drug_id, long question_id, long eoc_id, string label, string value, string type, DateTime date, string help_text = "", long? id = null, string required = "No", string prereq = "No", string text=null ) { Data.DSQ.Link item; if( help_text != null && help_text.Length >= 450 ) { return new ReturnObject { Error = true, Message = "The help text must be less than 450 characters." }; } var link = new DsqLink { Id = id ?? 0, DrugId = drug_id, QuestionId = question_id, EocId = eoc_id, Label = label, Value = type == "text" ? text : value, Date = date, HelpText = help_text, IsRequired = required.ToLowerInvariant() == "yes", HasPrereq = prereq.ToLowerInvariant() == "yes", LinkType = type }; // a nice and testable method call ObjectFactory.GetInstance<IDsqService>().SaveLink(link); Lib.Data.DSQ.Question question = new Lib.Data.DSQ.Question(link.QuestionId); return new ReturnObject() { Result = link, Redirect = new ReturnRedirectObject() { Hash = "admin/dsq/edit?id=" + drug_id + "§ion-id=" + question.SectionID }, Growl = new ReturnGrowlObject() { Type = "default", Vars = new ReturnGrowlVarsObject() { text = "You have successfully saved this link.", title = "Link Saved" } } }; }
public static ReturnObject Edit(HttpContext context, long section_id, string text, string field_type, int order, string viewtext = null, string subtext = null, string help_text = null, string dev_name = "", int required = 0, long? parent_id = null, string parent_checks = null, long? id = null, string eoc = null, string answers = null, string hide_answers = null, string show_children_answers = null, string hide_roles = null, string show_roles = null) { var item = new Lib.Data.DSQ.Question(id); item.SectionID = section_id; item.ParentID = parent_id; item.ParentChecks = parent_checks; item.Text = text; item.ViewText = viewtext; item.SubText = subtext; item.HelpText = help_text; item.DevName = dev_name; item.Required = (required == 1); item.FieldType = field_type; item.Order = order; item.Answers = (field_type == "EOC" ? eoc : answers); item.HideForAnswers = hide_answers; item.ShowChildrenForAnswers = show_children_answers; item.HideForRoles = hide_roles; item.ShowForRoles = show_roles; item.Save(); return new ReturnObject() { Result = item, Redirect = new ReturnRedirectObject() { Hash = "dev/dsq/questions/list" }, Growl = new ReturnGrowlObject() { Type = "default", Vars = new ReturnGrowlVarsObject() { text = "You have successfully saved this question.", title = "Question Saved" } } }; }
public static ReturnObject Edit(HttpContext context, string generic_name, long class_id, long? id = null, string rems_reason = null, string indication = null, long? system_id = null, string rems_website = null, string fda_number = null, DateTime? rems_approved = null, DateTime? rems_updated = null, bool active = false, bool new_version = false, string message = null, Newtonsoft.Json.Linq.JArray questions = null) { Lib.Data.Drug item = null; if (id > 0) item = new Lib.Data.Drug(id); else item = new Lib.Data.Drug(); var u = Framework.Security.Manager.GetUser(); bool approved = true; if( u.IsInGroup(Framework.Security.Group.FindByName("drugcompany")) ) { approved = false; new_version = true; } if (new_version && string.IsNullOrEmpty(message)) return new ReturnObject { Error = true, Message = "You must enter a message when you save a new version." }; if( Lib.Systems.Drugs.HasPendingChanges(item) ) return new ReturnObject { Error = true, Message = "You can not modify a drug that has pending changes." }; item.GenericName = generic_name; item.RemsReason = rems_reason; item.Indication = indication; item.ClassID = class_id; item.SystemID = system_id; item.RemsProgramUrl = rems_website; item.FdaApplicationNumber = fda_number; item.RemsApproved = rems_approved; item.RemsUpdated = rems_updated; item.Active = active; item.UpdatedByID = u.ID.Value; item.Updated = DateTime.Now; item.Save(); if (id <= 0) { new_version = true; message = "New Drug Created."; } Data.DrugVersion ver = null; if (new_version) { var last_version = Data.DrugVersion.FindLatestByDrug(item); ver = new Data.DrugVersion(); ver.DrugID = item.ID.Value; ver.Message = message; ver.Version = ((last_version == null) ? 1 : last_version.Version + 1); ver.Updated = DateTime.Now; ver.UpdatedBy = u.ID.Value; ver.Status = (approved ? "Approved" : "Pending"); if( approved ) { ver.Reviewed = DateTime.Now; ver.ReviewedBy = u.ID.Value; } // MJL - changed to always send notification no matter what (even if // it was auto approved. StringBuilder notificationMsg = new StringBuilder(); notificationMsg.Append(item.GenericName); notificationMsg.Append(" has new pending changes for you to review (version "); notificationMsg.Append(ver.Version); notificationMsg.Append(" - "); notificationMsg.Append(ver.Updated.ToShortDateString()); notificationMsg.Append(")"); // MJL - if the version was auto-approved (because user is admin), note // that in the message. if(approved) notificationMsg.Append(". This version was automatically approved."); var n = NotificationService.Create( item.GenericName + " Update", notificationMsg.ToString(), true, NotificationService.DataType.Drug, item.ID.Value); NotificationService.Send(n, Group.FindByName("admin"), NotificationService.Templates.NewsAndUpdates); ver.Save(); } if (questions != null) { var ids = new List<long>(); foreach (var o in questions) { var oid = o.Value<string>("id"); var ovalue = o.Value<object>("value"); long lid; if (!long.TryParse(oid, out lid)) continue; var question = new Lib.Data.DSQ.Question(lid); if (!question.ID.HasValue || question.ID.Value != lid) continue; ids.Add(lid); string v; #region Parse Value from Request if (ovalue == null) { v = null; } else if (ovalue.GetType() == typeof(string)) { v = (string)ovalue; } else if (ovalue.GetType() == typeof(Newtonsoft.Json.Linq.JValue)) { var t = (Newtonsoft.Json.Linq.JValue)ovalue; v = (string)t.Value; } else if (ovalue.GetType() == typeof(Newtonsoft.Json.Linq.JArray)) { var t = (Newtonsoft.Json.Linq.JArray)ovalue; v = ""; for (int i = 0; i < t.Count; i++) { if (!string.IsNullOrEmpty(v)) v += "\n"; v += (string)t[i]; } } else { return new ReturnObject() { Result = ovalue, Error = true, Message = "Invalid value for question [" + oid + "]. {" + question.Text + "} {" + ovalue.GetType().FullName + "}" }; } if (v != null && v.Trim() == "") v = null; #endregion var answer = Lib.Data.DSQ.Answer.FindByDrug(item, question); /* // if it's a text area, process any Markdown that might be present if(question.FieldType == "TextArea") v = markdownSvc.ToHtml(v); */ if (answer == null || answer.DrugID != item.ID.Value || answer.QuestionID != lid) { answer = new Data.DSQ.Answer(); answer.DrugID = item.ID.Value; answer.QuestionID = lid; answer.Value = null; answer.Save(); } if( new_version && answer.Value != v ) { var av = new Lib.Data.DSQ.AnswerVersion(); av.DSQAnswerID = answer.ID.Value; av.Value = v; av.Version = ver.Version; av.Save(); } if( approved ) { answer.Value = v; answer.Save(); } } if( approved ) { var lqs = Lib.Data.DSQ.Question.FindAll(); foreach (var lq in lqs) { if (lq == null || lq.ID == null || ids.Contains(lq.ID.Value)) continue; var a = Lib.Data.DSQ.Answer.FindByDrug(item, lq); if (a == null) continue; a.Delete(); } } } if( approved ) { item.DetermineEOC(); Lib.Systems.Lists.UpdateDrugLists( item ); } return new ReturnObject() { Result = item, Redirect = new ReturnRedirectObject { Hash = "admin/dsq/edit?id=" + item.ID.Value.ToString(CultureInfo.InvariantCulture) }, Growl = new ReturnGrowlObject { Type = "default", Vars = new ReturnGrowlVarsObject { text = "You have successfully saved this drug.", title = "Drug Saved" } }, Actions = new List<ReturnActionObject> { new ReturnActionObject { Type = "reset-unsaved" } } }; }