public static void PopulateViewBagWithOperatorSelectListItems(dynamic viewBag) { viewBag.QueryFieldTypeBooleanOperators = CreateSelectListItems( AspHelpers.CreateNoneSelectedSelectListItem(), Operators.IsTrue, Operators.IsFalse ); viewBag.QueryFieldTypeNumericOperators = CreateSelectListItems( AspHelpers.CreateNoneSelectedSelectListItem(), Operators.LessThan, Operators.LessThanOrEqual, Operators.Equals, Operators.NotEquals, Operators.GreaterThan, Operators.GreaterThanOrEqual ); viewBag.QueryFieldTypeDateOperators = CreateSelectListItems( AspHelpers.CreateNoneSelectedSelectListItem(), Operators.LessThan, Operators.LessThanOrEqual, Operators.Equals, Operators.NotEquals, Operators.GreaterThan, Operators.GreaterThanOrEqual ); viewBag.QueryFieldTypeTextOperators = CreateSelectListItems( AspHelpers.CreateNoneSelectedSelectListItem(), Operators.Equals, Operators.NotEquals ); viewBag.OneOfOperators = CreateSelectListItems( null, Operators.AnyOf ); }
protected IQueryable <T> ApplyBrowse <T>(IQueryable <T> q, string sortCol, IEnumerable <string> orderedValues, string sortDir, int?page, int?pageSize, IDictionary <string, string> colMapper = null) { ViewBag.TotalItemCount = q.Count(); bool isAscending = AspHelpers.IsSortDirAscending(sortDir); ViewBag.SortCol = sortCol; ViewBag.SortDir = sortDir; q = q.OrderByField(sortCol, orderedValues, isAscending); q = ApplyPagination(q, page, pageSize); return(q); }
public void ModelValidation_ReturnsNoErrors_WhenModelStateIsValid() { // Arrange var postDto = TestData.Activations.ContractActivationPostDto.Electromyography; // Act var modelValidation = AspHelpers.ValidateDto(postDto); // Assert modelValidation.IsValid.ShouldBeTrue(); }
public RequestForReassignmentViewModel(string suggestedReviewerId, string justificationKey, int?requestForReassignmentId, string comments, int workflowId, int regionId, IList <SelectListItem> userSelectItems, IList <Justification> justifications) { RequestForReassignmentId = requestForReassignmentId; SuggestedReviewerId = suggestedReviewerId; JustificationKey = justificationKey; Users = userSelectItems; Comments = comments; Justifications = AspHelpers.CreateSelectList(justifications); WorkflowId = workflowId; RegionId = regionId; }
public void ModelValidation_ReturnsNoErrors_WhenModelStateIsValid() { // Arrange var postDto = TestData.Exercises.ContractExercisePostDto; // Act var modelValidation = AspHelpers.ValidateDto(postDto); // Assert modelValidation.IsValid.ShouldBeTrue(); }
public void ModelValidation_PeakEmg_CannotBeNull() { // Arrange var postDto = new PostEmgResultDto(); // Act var modelValidation = AspHelpers.ValidateDtoProperty(postDto, nameof(postDto.PeakEmg)); // Assert modelValidation.IsValid.ShouldBeFalse(); modelValidation.Results.First().ErrorMessage.ShouldContain($"{nameof(postDto.PeakEmg)} field is required"); }
public void ModelValidation_RepetitionTempo_CannotBeNull() { // Arrange var postDto = new PostActivationDto { RepetitionTempo = null }; // Act var modelValidation = AspHelpers.ValidateDtoProperty(postDto, nameof(postDto.RepetitionTempo)); // Assert modelValidation.IsValid.ShouldBeFalse(); modelValidation.Results.First().ErrorMessage.ShouldContain($"{nameof(postDto.RepetitionTempo)} field is required"); }
public void ModelValidation_PeakEmg_CannotBeLessThanZero() { // Arrange var postDto = new PostEmgResultDto { PeakEmg = -1 }; // Act var modelValidation = AspHelpers.ValidateDtoProperty(postDto, nameof(postDto.PeakEmg)); // Assert modelValidation.IsValid.ShouldBeFalse(); modelValidation.Results.First().ErrorMessage.ShouldContain($"{nameof(postDto.PeakEmg)} must be between 0 and"); }
public void ModelValidation_RequiresShortName_WhenShortNameIsNullOrWhitespace(string shortName) { // Arrange var postDto = new PostExerciseDto { ShortName = shortName }; // Act var modelValidation = AspHelpers.ValidateDtoProperty(postDto, nameof(postDto.ShortName)); // Assert modelValidation.IsValid.ShouldBeFalse(); modelValidation.Results.First().ErrorMessage.ShouldContain($"{nameof(postDto.ShortName)} field is required"); }
public void ModelValidation_MuscleId_CannotBeNullOrWhitespace(string muscleId) { // Arrange var postDto = new PostActivationDto { MuscleId = muscleId }; // Act var modelValidation = AspHelpers.ValidateDtoProperty(postDto, nameof(postDto.MuscleId)); // Assert modelValidation.IsValid.ShouldBeFalse(); modelValidation.Results.First().ErrorMessage.ShouldContain($"{nameof(postDto.MuscleId)} field is required"); }
public void ModelValidation_ConcentricDuration_CannotBeLessThanZero() { // Arrange var postDto = new PostRepetitionTempoDto { ConcentricDuration = -1 }; // Act var modelValidation = AspHelpers.ValidateDtoProperty(postDto, nameof(postDto.ConcentricDuration)); // Assert modelValidation.IsValid.ShouldBeFalse(); modelValidation.Results.Count.ShouldBe(1); modelValidation.Results.First().ErrorMessage.ShouldContain($"{nameof(postDto.ConcentricDuration)} must be between 0 and"); }
public void ModelValidation_RequiresMaxLenghtOf30_ForLongNameProperty() { // Arrange var postDto = new PostExerciseDto { LongName = new string('a', 61) }; // Act var modelValidation = AspHelpers.ValidateDtoProperty(postDto, nameof(postDto.LongName)); // Assert modelValidation.IsValid.ShouldBeFalse(); modelValidation.Results.Count.ShouldBe(1); modelValidation.Results.First().ErrorMessage.ShouldContain("'60'"); }
public void ModelValidation_RangeOfMotion_MustBeBetween0And100(double value) { // Arrange var postDto = new PostActivationDto { RangeOfMotion = value }; // Act var modelValidation = AspHelpers.ValidateDtoProperty(postDto, nameof(postDto.RangeOfMotion)); // Assert modelValidation.IsValid.ShouldBeFalse(); modelValidation.Results.Count.ShouldBe(1); modelValidation.Results.First().ErrorMessage.ShouldContain("0"); modelValidation.Results.First().ErrorMessage.ShouldContain("100"); }
private static IList <SelectListItem> CreateSelectListItems(SelectListItem firstItem, params Operators[] operators) { var items = new List <SelectListItem>(); if (firstItem != null) { items.Add(firstItem); } foreach (var op in operators) { var item = new SelectListItem { Text = AspHelpers.GetDisplayName(op), Value = op.ToString() }; items.Add(item); } return(items); }
protected IQueryable <T> ApplySort <T>(IQueryable <T> q, string sortCol, string sortDir, IDictionary <string, string> colMapper = null) { var m = new Dictionary <string, string>(colMapper ?? NoMappings); if (!m.ContainsKey("CreatedAt")) { m["CreatedAt"] = "CreatedAtUtc"; } sortCol = StringHelpers.TrimOrNull(sortCol); bool isAscending = AspHelpers.IsSortDirAscending(sortDir); ViewBag.SortCol = sortCol; ViewBag.SortDir = sortDir; if (sortCol != null) { sortCol = m.FindOrMissing(sortCol, sortCol); q = q.OrderByField(sortCol, isAscending); } return(q); }
public async Task <JsonResult> Mark() { var md = await AspHelpers.BodyAsJsonObjectAsync <MarkData>(Request); var ret = new List <int>(); if (md != null && md.WorkflowIds != null && md.WorkflowIds.Length > 0) { var viewAction = md.Viewed ? WorkflowView.CommonActions.Seen : WorkflowView.CommonActions.Unread; foreach (var workflowId in md.WorkflowIds.Distinct()) { DB.WorkflowViews.Add(new WorkflowView { ActionAtUtc = DateTime.UtcNow, UserId = CurrentUserId, ViewAction = viewAction, WorkflowId = workflowId }); ret.Add(workflowId); } await DB.SaveChangesAsync(); } return(Json(ret)); }
public ActionResult Search(int?uloId, string pegasysDocumentNumber, string organization, int[] region, int[] zone, string fund, string[] baCode, string pegasysTitleNumber, string pegasysVendorName, string[] docType, string contractingOfficersName, string currentlyAssignedTo, string hasBeenAssignedTo, string awardNumber, string[] reasons, bool[] validity, string[] status, int[] reviews, bool?reassignableByMe, string sortCol = null, string sortDir = null, int?page = null, int?pageSize = null) { SetNoDataMessage(ConfigOptions.Value.NoSearchResults); var wfPredicate = PortalHelpers.GenerateWorkflowPredicate(this.User, uloId, pegasysDocumentNumber, organization, region, zone, fund, baCode, pegasysTitleNumber, pegasysVendorName, docType, contractingOfficersName, currentlyAssignedTo, hasBeenAssignedTo, awardNumber, reasons, validity, status, reviews, reassignableByMe); bool hasFilters = wfPredicate != null || !string.IsNullOrEmpty(Request.Query["f"]); if (!hasFilters) { wfPredicate = PredicateBuilder.Create <Workflow>(wf => false); } else if (wfPredicate == null) { wfPredicate = PredicateBuilder.Create <Workflow>(wf => true); } var workflows = ApplyBrowse( Workflows.Where(wfPredicate).AsNoTracking(), sortCol ?? nameof(Workflow.DueAtUtc), sortDir, page, pageSize).ToList(); var baCodes = Cacher.FindOrCreateValue( Cache.CreateKey(nameof(Search), "baCodes"), () => DB.UnliquidatedObligations.Select(u => u.Prog).Distinct().OrderBy(p => p).ToList().AsReadOnly(), PortalHelpers.MediumCacheTimeout ); var ReasonIncludedInReviewList = Cacher.FindOrCreateValue( Cache.CreateKey(nameof(Search), "ReasonIncludedInReviewList"), () => DB.UnliquidatedObligations.Select(u => u.ReasonIncludedInReview).Distinct().OrderBy(p => p).ToList().AsReadOnly(), PortalHelpers.MediumCacheTimeout ); var activityNames = GetOrderedActivityNameByWorkflowName().AtomEnumerable.ConvertAll(z => z.Value).Distinct().OrderBy().ToList(); var reviewListItems = Cacher.FindOrCreateValue(Cache.CreateKey(nameof(Search), "reviewListItems"), () => DB.Reviews.OrderByDescending(r => r.ReviewId).ConvertAll( r => new SelectListItem { Text = $"{r.ReviewName} (#{r.ReviewId}) - {AspHelpers.GetDisplayName(r.ReviewScopeId)} - {AspHelpers.GetDisplayName(r.ReviewTypeId)}", Value = r.ReviewId.ToString() }). ToList(). AsReadOnly(), PortalHelpers.ShortCacheTimeout ); var statuses = Cacher.FindOrCreateValue( "AllWorkflowStatusNames", () => { var names = new List <string>(); foreach (var wd in DB.WorkflowDefinitions.Where(wfd => wfd.IsActive == true)) { names.AddRange(wd.Description.WebActionWorkflowActivities.Select(z => z.ActivityName)); } return(names.Distinct().OrderBy()); }, PortalHelpers.MediumCacheTimeout); PopulateViewInfoIntoViewBag(workflows); return(View( "~/Views/Ulo/Search/Index.cshtml", new FilterViewModel( workflows, PortalHelpers.CreateDocumentTypeSelectListItems().SelectItems(docType), PortalHelpers.CreateZoneSelectListItems().SelectItems(zone), PortalHelpers.CreateRegionSelectListItems().SelectItems(region), baCodes, activityNames, statuses, ReasonIncludedInReviewList, reviewListItems, hasFilters, new[] { new SelectListItem("Yes", "true"), new SelectListItem("No", "false") }.SelectItems(validity) ))); }