public async Task <SaveForecastsResponse> SaveForecasts(ForecastMonthDto forecastMonth) { var request = new SaveForecastsRequest { ForecastMonthDto = forecastMonth }; var result = await TrySendAsync(request, () => "An error occured while saving forecastMonth"); return(result); }
public void MergeForecastMonth(IForecastRegistrationViewModel vm, ForecastMonthDto forecastMonth) { vm.ForecastMonthId = forecastMonth.Id; vm.ForecastMonthIsLocked = forecastMonth.IsLocked; vm.Initializing = true; foreach (var forecast in forecastMonth.ForecastDtos) { _guiMapper.Map(forecast, vm); } vm.ProjectRegistrations.InitializeDirtyCheck(); vm.Initializing = false; vm.CalculateTotals(); }
/// <summary> /// Determines if month is locked. /// Business rule: /// If currentdate exceeds currentlockdate the previous month /// is by default locked unless stated explicitly that it is unlocked by UnLocked property /// </summary> /// <param name="dto"></param> /// <param name="forecastMonth"></param> public virtual void SetDtoIsLocked(ForecastMonthDto dto, ForecastMonth forecastMonth) { var now = Now; // Is explicitly set to allow update if (forecastMonth != null) { dto.IsLocked = forecastMonth.IsLocked; return; } // Forecast is null. var lockDate = ForecastMonth.CreateLockedFrom(dto.Month, dto.Year, _domainSettings.PastMonthsDayLock); dto.IsLocked = now > lockDate; }
public async void Execute(IForecastRegistrationViewModel vm) { if (!vm.IsValid()) { return; } vm.IsBusy = true; var forecastMonthDto = new ForecastMonthDto { Id = vm.ForecastMonthId, Month = vm.SelectedDate.Month, Year = vm.SelectedDate.Year, UserId = _selectedUserHandler.UserId, CreatedById = _userSession.CurrentUser.Id, ForecastDtos = vm.DateColumns .GetItemsToSave(vm.ProjectForecastTypeId) .Select(col => new ForecastDto { Date = col.Date, DedicatedForecastTypeHours = col.SelectedForecastTypeDedicatedHours, ForecastType = col.ForecastType.ToServerDto(), ForecastProjectHoursDtos = col.ProjectHoursWithValue.Select(BuildForecastProjectHoursDto).ToList() }).ToList() }; var saveResponse = await _forecastService.SaveForecasts(forecastMonthDto); // Null if an error occured if (saveResponse != null) { vm.ForecastMonthId = saveResponse.ForecastMonthId; } vm.IsBusy = false; vm.InitializeDirtyCheck(); vm.RaiseCanExecuteActions(); ApplicationCommands.GetForecastStatistics.Execute(vm.SelectedDate); }
private ForecastMonthDto ToForecastDtoObject(ForecastMonth forecastMonth, ForecastsByUserAndMonthRequest request) { ForecastMonthDto result = null; if (forecastMonth == null) { // Can be null, if not entered earlier. Resolution add to db and set UnLocked to true result = new ForecastMonthDto { Id = 0, Month = request.ForecastMonth, Year = request.ForecastYear, ForecastDtos = new List <ForecastDto>() }; } else { result = Mapper.Map <ForecastMonth, ForecastMonthDto>(forecastMonth); } SetDtoIsLocked(result, forecastMonth); return(result); }
public void Execute_OneOfEachPresenceTypeToSave_CallSaveForecastsWithMappedDtos() { // Arrange var frame = new DispatcherFrame(); var fixture = InitializeFixture(); fixture.Behaviors.Add(new OmitOnRecursionBehavior()); fixture.Inject(new DateTime(2013, 1, 1)); fixture.Inject(ForecastTestData.ProjectHoursOnlyForecastType); fixture.Inject(ForecastTestData.ForecastTypesList); fixture.Register(() => User.Create(string.Empty, string.Empty, 10, null, null)); var user = fixture.Create <User>(); var userSessionMock = fixture.Freeze <Mock <IUserSession> >(); userSessionMock.SetupGet(x => x.CurrentUser).Returns(user); var selectedUserHandlerMock = FreezeMock <ForecastRegistrationSelectedUserHandler>(); selectedUserHandlerMock.SetupGet(x => x.UserId).Returns(10); ForecastMonthDto passedForecastMonth = null; // Hookup callback for value assertion var forecastServiceMock = fixture.Freeze <Mock <IForecastService> >(); forecastServiceMock .Setup(x => x.SaveForecasts(It.IsAny <ForecastMonthDto>())) .ReturnsAsync(new SaveForecastsResponse { ForecastMonthId = 123 }) .Callback <ForecastMonthDto>((fmonth) => { passedForecastMonth = fmonth; }); fixture.Register(() => new ForecastRegistrationDateColumn(new DateTime(2013, 1, 1))); fixture.Register(() => new ProjectHourRegistration(fixture.Create <ProjectRegistration>())); var hourReg = fixture.Create <ProjectHourRegistration>(); hourReg.Hours = 7.5m; fixture.Register(() => new ForecastTypeRegistration(ForecastTestData.ProjectHoursOnlyForecastType, ForecastTestData.ForecastTypesList)); var dateColumn = fixture.Create <ForecastRegistrationDateColumn>(); dateColumn.AddProjectHours(hourReg); var dateColumns = fixture.Create <ForecastDateColumns>(); dateColumns.Add(dateColumn); var vm = fixture.Create <Mock <IForecastRegistrationViewModel> >(); vm.SetupGet(x => x.ForecastMonthId).Returns(1); vm.Setup(x => x.IsValid()).Returns(true); vm.SetupGet(x => x.SelectedDate).Returns(new DateTime(2013, 1, 1)); vm.SetupGet(x => x.DateColumns).Returns(dateColumns); var sut = fixture.Create <SaveForecastCommandHandler>(); // Act sut.Execute(vm.Object); // Assert vm.VerifySet(x => x.ForecastMonthId = 123); vm.VerifyAll(); //userSessionMock.VerifyAll(); selectedUserHandlerMock.VerifyAll(); forecastServiceMock.VerifyAll(); Assert.That(passedForecastMonth.Id, Is.EqualTo(1)); Assert.That(passedForecastMonth.UserId, Is.EqualTo(10)); Assert.That(passedForecastMonth.Month, Is.EqualTo(1)); Assert.That(passedForecastMonth.Year, Is.EqualTo(2013)); }