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 void SetupTestObjects() { _dsqRepo = MockRepository.GenerateMock<IDsqRepository>(); _dsqService = new DsqService(_dsqRepo); _link = new DsqLink { Date = DateTime.Now, DrugId = 1, EocId = 1, HelpText = "Help Text", Label = "Label", QuestionId = 1, Value = "Test" }; }
protected void Page_Init(object sender, EventArgs e) { long id = (Request.QueryString["id"] != null) ? Int64.Parse(Request.QueryString["id"]) : 0; long drugId = Int64.Parse(Request.QueryString["drug-id"]); long questionId = Int64.Parse(Request.QueryString["question-id"]); Link = (id > 0 ) ? _dsqSvc.GetLink(id) : new DsqLink { Date = DateTime.Now, DrugId = drugId, QuestionId = questionId }; Eocs = _complianceSvc.GetEocs().ToList(); }
public void should_insert_new_dsq_link_into_db() { // arrange DsqLink link = new DsqLink { Date = DateTime.Now, DrugId = 1, EocId = 1, HelpText = "Help Text", Label = "Label", QuestionId = 1, Value = "Test" }; // act _dsqRepo.SaveLink(link); // assert link.Id.Should().NotBe(0); }
public void SaveLink(DsqLink link) { // save the link _dsqRepo.SaveLink(link); // now we need to update the eoc status of the question. first, we just // clear any existing value. _dsqRepo.DeleteEoc(link.DrugId, link.QuestionId); // now we'll see if there is a need to set value by loading all of the links // for the question and seeing if any of them have a required eoc. long eocId = ( from l in _dsqRepo.GetLinks(link.DrugId, link.QuestionId) where l.HasPrereq && l.EocId > 0 select l.EocId).FirstOrDefault(); // if eocId > 0, then we need to indicate that this question has an EOC. _dsqRepo.AddEoc(new DsqEoc { DrugId = link.DrugId, QuestionId = link.QuestionId, EocId = eocId, }); }