/// <summary> /// Updates the solution detail. /// </summary> /// <param name="solutionRequestDto">The solution request dto.</param> /// <param name="solutions">The solutions.</param> /// <returns></returns> /// <exception cref="PowerDesignProException">SolutionNameExist</exception> private ProjectSolutionDto UpdateSolutionDetail(ProjectSolutionDto solutionRequestDto, IQueryable <Solution> solutions, string userName) { var solutionCount = solutions.Count( s => s.ID != solutionRequestDto.SolutionID && s.SolutionName.Equals(solutionRequestDto.SolutionName, StringComparison.InvariantCultureIgnoreCase) && s.Active); if (solutionCount > 0) { throw new PowerDesignProException("SolutionNameExist", Message.ProjectSolution); } var solution = _solutionRepository.Find(solutionRequestDto.SolutionID); // mapping solution entity _solutionRequestDtoToSolutionEntityMapper.UpdateMap(solutionRequestDto, solution, null, userName); // mapping Solution child Entity (SolutionSetup) _solutionSetupRequestDtoToSolutionSetupEntityMapper.UpdateMap(solutionRequestDto.BaseSolutionSetupDto.SolutionSetupMappingValuesDto, solution.SolutionSetup.FirstOrDefault()); solution.SolutionSetup.FirstOrDefault().RegulatoryFilter = string.Join(";", solutionRequestDto.BaseSolutionSetupDto.SolutionSetupMappingValuesDto.SelectedRegulatoryFilterList.Select(x => x.Id + ":" + x.ItemName + ":" + x.LanguageKey).ToArray()); solution.Project.ModifiedBy = solution.ModifiedBy; solution.Project.ModifiedDateTime = solution.ModifiedDateTime; var result = _solutionRepository.Update(solution); _solutionRepository.Commit(); return(new ProjectSolutionDto { SolutionID = result.ID }); }
public HttpResponseMessage SaveSolutionDetail(ProjectSolutionDto projectSolutionResponseDto) { return(CreateHttpResponse(() => { return Request.CreateResponse(_projectSolutionProcessor.SaveSolutionDetail(projectSolutionResponseDto, UserID, UserName)); })); }
/// <summary> /// Get solution setup for existing solution /// </summary> /// <param name="userID"></param> /// <param name="projectID"></param> /// <param name="solutionID"></param> /// <returns></returns> public ProjectSolutionDto LoadSolutionSetupForExistingSolution(string userID, int projectID, int solutionID, string userName = "") { var solution = _solutionRepository.GetSingle(x => x.ID == solutionID && x.ProjectID == projectID && x.Active); var readOnlyAccess = false; if (!string.IsNullOrEmpty(solution.OwnedBy)) { if (!solution.OwnedBy.Equals(userName, StringComparison.InvariantCultureIgnoreCase)) { readOnlyAccess = true; } else { readOnlyAccess = false; } } else { readOnlyAccess = true; } var response = new ProjectSolutionDto { ProjectID = solution.ProjectID, SolutionID = solution.ID, SolutionName = solution.SolutionName, SpecRefNumber = solution.SpecRefNumber, Description = solution.Description, IsReadOnlyAccess = readOnlyAccess, BaseSolutionSetupDto = new BaseSolutionSetupDto() }; var solutionSetup = solution.SolutionSetup.FirstOrDefault(); if (solutionSetup != null) { var solutionDetail = _solutionSetupToProjectSolutionSetupResponseDtoMapper.AddMap(solution.SolutionSetup.FirstOrDefault()); response.BaseSolutionSetupDto = new BaseSolutionSetupDto { SolutionSetupMappingValuesDto = solutionDetail }; if (!string.IsNullOrEmpty(solutionSetup.RegulatoryFilter)) { response.BaseSolutionSetupDto.SolutionSetupMappingValuesDto.SelectedRegulatoryFilterList = solutionSetup .RegulatoryFilter.Split(';').Select(x => new RegulatoryFilterDto { Id = Convert.ToInt32(x.Split(':')[0]), ItemName = x.Split(':').Length > 1 ? x.Split(':')[1]:"", LanguageKey = x.Split(':').Length > 2 ? x.Split(':')[2]: string.Concat("tregulatoryFilterList.", x.Split(':')[1].Replace(" ", "")) }); } } return(response); }
public void SaveSolutionDetail_SaveSolutionExist(int projectId, string userId, string solutionName, string userName) { _solutionRepository.GetAll(s => s.ProjectID == projectId).ReturnsForAnyArgs(SolutionList()); var solutionRequest = new ProjectSolutionDto { SolutionName = solutionName }; var result = _projectSolutionProcessor.SaveSolutionDetail(solutionRequest, userId, userName); _solutionRepository.Add(Arg.Any <Solution>()).DidNotReceive(); }
public void SaveSolutionDetail_UpdateSolutionExist(int projectId, string userId, string userName) { _solutionRepository.GetAll(p => p.ProjectID == projectId).ReturnsForAnyArgs(SolutionList()); var solutionRequest = new ProjectSolutionDto { SolutionID = 2, SolutionName = "Test_Solution_1" }; var result = _projectSolutionProcessor.SaveSolutionDetail(solutionRequest, userId, userName); _solutionRepository.Update(Arg.Any <Solution>()).DidNotReceive(); }
/// <summary> /// Save solution details /// </summary> /// <param name="solutionSetupDto"></param> /// <param name="userId"></param> /// <returns></returns> public ProjectSolutionDto SaveSolutionDetail(ProjectSolutionDto projectSolutionResponseDto, string userID, string userName) { var solutions = _solutionRepository.GetAll(s => s.ProjectID == projectSolutionResponseDto.ProjectID && s.Active); if (projectSolutionResponseDto.SolutionID == 0) { return(AddSolutionDetail(projectSolutionResponseDto, solutions, userName)); } else { return(UpdateSolutionDetail(projectSolutionResponseDto, solutions, userName)); } }
public void SaveSolutionDetail_UpdateSuccessfully(int projectId, string userId, string solutionName, int solutionId, string userName) { _solutionRepository.GetAll(p => p.ProjectID == projectId).ReturnsForAnyArgs(SolutionList()); var solutionRequest = new ProjectSolutionDto { ProjectID = projectId, SolutionID = solutionId, SolutionName = solutionName, Description = "Test_Desc", SpecRefNumber = "Test_SpecRefNumber", BaseSolutionSetupDto = new BaseSolutionSetupDto { SolutionSetupMappingValuesDto = new BaseSolutionSetupMappingValuesDto { AmbientTemperatureID = 1, ElevationID = 1, VoltagePhaseID = 1, FrequencyID = 1, VoltageNominalID = 1, VoltageSpecificID = 1, UnitsID = 1, MaxRunningLoadID = 1, VoltageDipID = 1, VoltageDipUnitsID = 1, FrequencyDipID = 1, FrequencyDipUnitsID = 1, ContinuousAllowableVoltageDistortionID = 1, MomentaryAllowableVoltageDistortionID = 1, EngineDutyID = 1, FuelTypeID = 1, SolutionApplicationID = 1, EnclosureTypeID = 1, DesiredSoundID = 1, FuelTankID = 1, DesiredRunTimeID = 1, LoadSequenceCyclic1ID = 1, LoadSequenceCyclic2ID = 1, SelectedRegulatoryFilterList = new List <RegulatoryFilterDto> { new RegulatoryFilterDto { Id = 1, } } } } }; var updatedSolution = new Solution { ID = solutionId, SolutionName = solutionName, }; _solutionRepository.Find(solutionId).ReturnsForAnyArgs(SolutionList().FirstOrDefault(x => x.ID == solutionRequest.SolutionID)); _solutionRepository.Update(Arg.Any <Solution>()).Returns(updatedSolution); var actualResult = _projectSolutionProcessor.SaveSolutionDetail(solutionRequest, userId, userName); Assert.AreEqual(updatedSolution.ID, actualResult.SolutionID); }