protected async Task HandleSubmit() { PeriodVMEditContext = new EditContext(AdminPeriodVM); if (PeriodVMEditContext.Validate()) { var period = (await PeriodService.GetAsync(x => x.Year == AdminPeriodVM.PeriodeStartDate.Year)).FirstOrDefault(); if (period != null) { period.Description = AdminPeriodVM.Description.Trim(); period.PeriodeStartDate = AdminPeriodVM.PeriodeStartDate; period.PeriodeEndDate = AdminPeriodVM.PeriodeEndDate; period.PeriodValue = (decimal)AdminPeriodVM.PeriodValue; PeriodService.Update(period); } else { period = new Period { Year = AdminPeriodVM.PeriodeStartDate.Year, Description = AdminPeriodVM.Description.Trim(), PeriodeStartDate = AdminPeriodVM.PeriodeStartDate, PeriodeEndDate = AdminPeriodVM.PeriodeEndDate, PeriodValue = (decimal)AdminPeriodVM.PeriodValue, BudgetFrames = new List <BudgetFrame>() }; var regions = await RegionService.GetAsync(); var services = await ServiceService.GetAsync(x => x.ServiceTypeDate <= AdminPeriodVM.PeriodeStartDate && x.IsActive); foreach (var region in regions) { foreach (var service in services) { period.BudgetFrames.Add( new BudgetFrame { RegionId = region.Id, Year = AdminPeriodVM.PeriodeStartDate.Year, Service = service, Head = 0, Value = 0 }); } } await PeriodService.AddAsync(period); } await PeriodService.SaveChangesAsync(AppUser.Instance.FullName); PeriodVMs = Mapper.Map <IEnumerable <PeriodVM> >(await PeriodService.GetAsync()); ToggleView(); } StateHasChanged(); }
public async Task <IActionResult> List(int id) => Ok(await _regionsService.GetAsync(id));