private bool Validate(QueryModel m) { m.SetVisibility(); DateTime dt = DateTime.MinValue; if (m.StartDateVisible) if (!DateTime.TryParse(m.StartDate, out dt) || dt.Year <= 1900 || dt.Year >= 2200) m.Errors.Add("StartDate", "invalid"); if (m.EndDateVisible && m.EndDate.HasValue()) if (!DateTime.TryParse(m.EndDate, out dt) || dt.Year <= 1900 || dt.Year >= 2200) m.Errors.Add("EndDate", "invalid"); int i = 0; if (m.DaysVisible && !int.TryParse(m.Days, out i)) m.Errors.Add("Days", "must be integer"); if (i > 10000) m.Errors.Add("Days", "days > 1000"); if (m.AgeVisible && !int.TryParse(m.Age, out i)) m.Errors.Add("Age", "must be integer"); if (m.TagsVisible && string.Join(",", m.Tags).Length > 500) m.Errors.Add("tagvalues", "too many tags selected"); if (m.CodesVisible && m.CodeValues.Length == 0) m.Errors.Add("CodeValues", "must select item(s)"); if (m.NumberVisible && !m.NumberValue.HasValue()) m.Errors.Add("NumberValue", "must have a number value"); else { float f; if (m.NumberVisible && m.NumberValue.HasValue()) if (!float.TryParse(m.NumberValue, out f)) m.Errors.Add("NumberValue", "must have a valid number value (no decoration)"); } if (m.DateVisible && !m.Comparison.EndsWith("Equal")) if (!DateTime.TryParse(m.DateValue, out dt) || dt.Year <= 1900 || dt.Year >= 2200) m.Errors.Add("DateValue", "need valid date"); if (m.Comparison == "Contains") if (!m.TextValue.HasValue()) m.Errors.Add("TextValue", "cannot be empty"); return m.Errors.Count == 0; }
public JsonResult SelectCondition(int id, string ConditionName) { var m = new QueryModel { ConditionName = ConditionName, SelectedId = id }; m.LoadScratchPad(); m.SetVisibility(); m.TextValue = ""; m.Comparison = ""; m.IntegerValue = ""; m.DateValue = ""; m.CodeValue = ""; m.CodeValues = new string[0]; m.Days = ""; m.Age = ""; m.Program = 0; m.Quarters = ""; m.StartDate = ""; m.EndDate = ""; return Json(m); }