コード例 #1
0
        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());
        }
コード例 #2
0
ファイル: clsAgency.cs プロジェクト: iamitkapil/TFSWAy1.0
        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");
        }
コード例 #3
0
 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));
 }