Example #1
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var errors = new List <ValidationResult>();

            if (TechnicalAssistanceRequestSimples != null)
            {
                var reportedYears            = TechnicalAssistanceRequestSimples.Select(x => x.FiscalYear).Distinct().OrderByDescending(x => x).ToList();
                var reportedYearsMissingData = reportedYears?.Select(x => x).Where(x => TechnicalAssistanceRequestSimples.Any(y => y.FiscalYear == x && y.TechnicalAssistanceTypeID == null)).ToList();
                reportedYearsMissingData?.ForEach(x => errors.Add(new ValidationResult($"{x} has rows missing a value for Assistance Type.")));
            }
            return(errors);
        }
Example #2
0
        public void UpdateModel(FirmaSession currentFirmaSession, List <TechnicalAssistanceRequestUpdate> currentTechnicalAssistanceRequests, IList <TechnicalAssistanceRequestUpdate> allTechnicalAssistanceRequests, ProjectUpdateBatch projectUpdateBatch)
        {
            var userCanAllocate = new ProjectUpdateAdminFeatureWithProjectContext().HasPermission(currentFirmaSession, projectUpdateBatch.Project).HasPermission;
            var updatedTechnicalAssistanceRequests = TechnicalAssistanceRequestSimples != null?
                                                     TechnicalAssistanceRequestSimples.Select(x => new TechnicalAssistanceRequestUpdate(x.TechnicalAssistanceRequestID, projectUpdateBatch.ProjectUpdateBatchID, x.FiscalYear, x.PersonID, x.TechnicalAssistanceTypeID.Value, x.HoursRequested, x.HoursAllocated, x.HoursProvided, x.Notes)).ToList() :
                                                         new List <TechnicalAssistanceRequestUpdate>();

            var databaseEntities = HttpRequestStorage.DatabaseEntities;

            currentTechnicalAssistanceRequests.Merge(updatedTechnicalAssistanceRequests, allTechnicalAssistanceRequests,
                                                     (x, y) => x.TechnicalAssistanceRequestUpdateID == y.TechnicalAssistanceRequestUpdateID,
                                                     (x, y) =>
            {
                x.ProjectUpdateBatchID      = y.ProjectUpdateBatchID;
                x.FiscalYear                = y.FiscalYear;
                x.PersonID                  = y.PersonID;
                x.TechnicalAssistanceTypeID = y.TechnicalAssistanceTypeID;
                x.HoursRequested            = y.HoursRequested;
                x.HoursAllocated            = userCanAllocate ? y.HoursAllocated : x.HoursAllocated;
                x.HoursProvided             = userCanAllocate ? y.HoursProvided : x.HoursProvided;
                x.Notes = y.Notes;
            }, databaseEntities);
        }