public IActionResult UpdateAgency(int id, [FromForm] Agency agency) { if (id != agency.Id) { return(BadRequest()); } try { _agencyRepository.UpdateAgency(agency); } catch (DbUpdateConcurrencyException) { if (!AgencyExists(agency.Id)) { return(NotFound()); } } catch (DbUpdateException ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); throw; } catch (SqlException ex) { var sqlException = ex.GetBaseException() as SqlException; if (sqlException != null) { switch (sqlException.Number) { case 2627: // Unique constraint error break; case 547: // Constraint check violation break; case 2601: // Duplicated key row error break; default: throw; } } } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); throw; } return(NoContent()); }
public async Task <string> UpdateAgency(Agency agency) { // ProjectCompanyDetail projectcompanydet Agency existingagency = AgencyRepository.GetAgencys().SingleOrDefault(p => p.AgencyId == agency.AgencyId); if (existingagency == default(Agency)) { return("agency doesn't exist"); } int updateagency = await AgencyRepository.UpdateAgency(agency); return(updateagency > 0 ? "Successfully updated Agency" : "Updation failed"); }
public IActionResult Edit(Agency abs) { if (ModelState.IsValid) { abs.ModifiedBy = _admin.Fullname; Agency AgencyToUpdate = _AgencyRepository.GetAgencyById(abs.Id); if (AgencyToUpdate == null) { return(NotFound()); } _AgencyRepository.UpdateAgency(AgencyToUpdate, abs); return(RedirectToAction("index")); } return(View(abs)); }