public async Task <ApiResult <List <AdminAlertListDto> > > UpdateAlert(AdminAlertListDto dto) { var response = await _http.PostAsJsonAsync($"{Constants.ControllerNames.Alerts}/{Constants.Routes.Update}/{Constants.RoleNames.Admin}", dto); if (!response.IsSuccessStatusCode) { return(new ApiResult <List <AdminAlertListDto> > { Successful = false, Error = "Something went wrong when trying to communicate with the server." }); } return(await response.Content.ReadFromJsonAsync <ApiResult <List <AdminAlertListDto> > >()); }
public async Task <ApiResult <List <AdminAlertListDto> > > UpdateAlert(AdminAlertListDto dto) { try { var alert = _context.ApplicationAlerts.FirstOrDefault(a => a.Id == dto.Id); alert.Read = dto.Read; alert.AddressedBy = dto.AddressedBy; alert.Archived = dto.Archived; _context.Alerts.Update(alert); await _context.SaveChangesAsync(); return(GetAdminAlerts()); } catch (Exception ex) { _logger.LogError("An error occured when trying to updating alerts to the database:\n" + ex.Message); return(new ApiResult <List <AdminAlertListDto> > { Successful = false, Error = "An error occured when trying to update alerts to the database." }); } }
public IActionResult UpdateAdminAlerts([FromBody] AdminAlertListDto dto) { return(new ObjectResult(_alertService.UpdateAlert(dto))); }
protected async Task DeleteAlert(AdminAlertListDto alert) { alert.Archived = true; //alert.AddressedBy = await _alertService.UpdateAlert(alert); }