public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var errors = new List <ValidationResult>(); var emptyRows = ProjectFundingSourceExpenditures?.Where(x => x.CalendarYearExpenditures.All(y => !y.MonetaryAmount.HasValue)); if (emptyRows?.Any() ?? false) { errors.Add(new ValidationResult($"The {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} Update could not be saved because there are blank rows. Enter a value in all fields or delete funding sources for which there is no expenditure data to report.")); } // Expenditures note is required if no expenditures to enter is selected if (!HasExpenditures && string.IsNullOrWhiteSpace(ExpendituresNote)) { errors.Add(new ValidationResult($"The {FieldDefinitionEnum.Project.ToType().GetFieldDefinitionLabel()} could not be saved, Expenditures Notes are required if no expenditures are entered.")); } return(errors); }
public void UpdateModel(List <ProjectFirmaModels.Models.ProjectFundingSourceExpenditure> currentProjectFundingSourceExpenditures, IList <ProjectFirmaModels.Models.ProjectFundingSourceExpenditure> allProjectFundingSourceExpenditures, ProjectFirmaModels.Models.Project project) { var projectFundingSourceExpendituresUpdated = new List <ProjectFirmaModels.Models.ProjectFundingSourceExpenditure>(); if (ProjectFundingSourceExpenditures != null) { // Completely rebuild the list projectFundingSourceExpendituresUpdated = ProjectFundingSourceExpenditures.Where(x => x.IsRelevant).SelectMany(x => x.ToProjectFundingSourceExpenditures()).ToList(); } var databaseEntities = HttpRequestStorage.DatabaseEntities; project.ExpendituresNote = ExpendituresNote; currentProjectFundingSourceExpenditures.Merge(projectFundingSourceExpendituresUpdated, allProjectFundingSourceExpenditures, (x, y) => x.ProjectID == y.ProjectID && x.FundingSourceID == y.FundingSourceID && x.CalendarYear == y.CalendarYear, (x, y) => x.ExpenditureAmount = y.ExpenditureAmount, databaseEntities); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var errors = new List <ValidationResult>(); if (ProjectFundingSourceExpenditures == null) { ProjectFundingSourceExpenditures = new List <ProjectFundingSourceExpenditureBulk>(); } var projectFundingSourceExpenditureBulks = ProjectFundingSourceExpenditures.Where(x => x.IsRelevant).ToList(); if (HasExpenditures && !projectFundingSourceExpenditureBulks.Any()) { errors.Add(new ValidationResult("Please enter your expenditures")); } if (!HasExpenditures && string.IsNullOrWhiteSpace(Explanation)) { errors.Add(new ValidationResult("Please enter an explanation why you do not have any expenditures")); } return(errors); }
public void UpdateModel(ProjectFirmaModels.Models.Project project, List <ProjectFirmaModels.Models.ProjectFundingSourceExpenditure> currentProjectFundingSourceExpenditures, IList <ProjectFirmaModels.Models.ProjectFundingSourceExpenditure> allProjectFundingSourceExpenditures) { var databaseEntities = HttpRequestStorage.DatabaseEntities; databaseEntities.ProjectExemptReportingYearUpdates.Load(); databaseEntities.ProjectRelevantCostTypes.Load(); var projectFundingSourceExpendituresUpdated = new List <ProjectFirmaModels.Models.ProjectFundingSourceExpenditure>(); if (ProjectFundingSourceExpenditures != null) { // Completely rebuild the list projectFundingSourceExpendituresUpdated = ProjectFundingSourceExpenditures.Where(x => x.IsRelevant).SelectMany(x => x.ToProjectFundingSourceExpendituresSetNullToZero()).ToList(); } currentProjectFundingSourceExpenditures.Merge(projectFundingSourceExpendituresUpdated, allProjectFundingSourceExpenditures, (x, y) => x.ProjectID == y.ProjectID && x.FundingSourceID == y.FundingSourceID && x.CostTypeID == y.CostTypeID && x.CalendarYear == y.CalendarYear, (x, y) => x.ExpenditureAmount = y.ExpenditureAmount, databaseEntities); var currentProjectRelevantCostTypes = project.GetExpendituresRelevantCostTypes(); var allProjectRelevantCostTypes = databaseEntities.AllProjectRelevantCostTypes.Local; var projectRelevantCostTypes = new List <ProjectRelevantCostType>(); if (ProjectRelevantCostTypes != null) { // Completely rebuild the list projectRelevantCostTypes = ProjectRelevantCostTypes.Where(x => x.IsRelevant) .Select(x => new ProjectRelevantCostType(x.ProjectRelevantCostTypeID, x.ProjectID, x.CostTypeID, ProjectRelevantCostTypeGroup.Expenditures.ProjectRelevantCostTypeGroupID)) .ToList(); } currentProjectRelevantCostTypes.Merge(projectRelevantCostTypes, allProjectRelevantCostTypes, (x, y) => x.ProjectID == y.ProjectID && x.CostTypeID == y.CostTypeID && x.ProjectRelevantCostTypeGroupID == y.ProjectRelevantCostTypeGroupID, databaseEntities); project.ExpendituresNote = ProjectFundingSourceExpenditures != null && ProjectFundingSourceExpenditures.Any() ? null : Explanation; }