public async Task <ActionResult> EditSharedGovernor(EditSharedGovernorViewModel model) { if (ModelState.IsValid) { await _governorsWriteService.UpdateDatesAsync(model.Governor.Id, model.Governor.AppointmentStartDate.ToDateTime().Value, model.Governor.AppointmentEndDate.ToDateTime().Value, User); var url = $"{Url.RouteUrl("EstabDetails", new { id = model.Urn, saved = true })}#school-governance"; return(Redirect(url)); } var governor = await _governorsReadService.GetGovernorAsync(model.Governor.Id, User); var roleName = (await _cachedLookupService.GovernorRolesGetAllAsync()).Single(x => x.Id == governor.RoleId.Value).Name; model.Governor = await SharedGovernorViewModel.MapFromGovernor(governor, model.Urn.Value, _cachedLookupService); model.GovernorType = roleName; await _layoutHelper.PopulateLayoutProperties(model, model.Urn.Value, null, User); return(View(model)); }
public async Task <ActionResult> DeleteOrRetireGovernor(GovernorsGridViewModel viewModel) { if (ModelState.IsValid) { if (viewModel.Action == "Save") // retire selected governor with the chosen appt. end date { if (viewModel.GovernorShared.HasValue && viewModel.GovernorShared.Value && viewModel.EstablishmentUrn.HasValue) { var sharedGovernor = await _governorsReadService.GetGovernorAsync(viewModel.RemovalGid.Value, User); var appointment = sharedGovernor.Appointments.Single(a => a.EstablishmentUrn == viewModel.EstablishmentUrn.Value); var response = await _governorsWriteService.UpdateSharedGovernorAppointmentAsync(viewModel.RemovalGid.Value, viewModel.EstablishmentUrn.Value, appointment.AppointmentStartDate.Value, viewModel.RemovalAppointmentEndDate.ToDateTime().Value, User); response.ApplyToModelState(ControllerContext); } else { var response = await _governorsWriteService.UpdateDatesAsync(viewModel.RemovalGid.Value, viewModel.RemovalAppointmentEndDate.ToDateTime().Value, User); if (!response.Success) { if (response.Errors.Length == 0) { throw new TexunaApiSystemException($"The TEX-API said no (but gave no details!)..."); } response.ApplyToModelState(ControllerContext); } } } else if (viewModel.Action == "Remove") // mark the governor record as deleted { if (viewModel.GovernorShared.GetValueOrDefault() && viewModel.EstablishmentUrn.HasValue) { await _governorsWriteService.DeleteSharedGovernorAppointmentAsync(viewModel.RemovalGid.Value, viewModel.EstablishmentUrn.Value, User); } else { await _governorsWriteService.DeleteAsync(viewModel.RemovalGid.Value, User); } } else { throw new InvalidParameterException($"The parameter for action is invalid: '{viewModel.Action}'"); } if (ModelState.IsValid) { var url = viewModel.EstablishmentUrn.HasValue ? $"{Url.RouteUrl("EstabDetails", new { id = viewModel.EstablishmentUrn, saved = true })}#school-governance" : $"{Url.RouteUrl("GroupDetails", new { id = viewModel.GroupUId, saved = true })}#governance"; return(Redirect(url)); } } await _layoutHelper.PopulateLayoutProperties(viewModel, viewModel.EstablishmentUrn, viewModel.GroupUId, User); return(await Edit(viewModel.GroupUId, viewModel.EstablishmentUrn, viewModel.RemovalGid, null)); }