public async Task <ActionResult> Edit(Guid id, EditCountryViewModel request) { if (!ModelState.IsValid) { Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(request)); } if (!id.Equals(request.CountryId)) { Alert("Invalid Request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(request)); } try { var countryUpdateRequest = new UpdateCountryRequest { Id = request.CountryId, Name = request.Name, Description = request.Description }; var result = await _countryService.Update(id, countryUpdateRequest); if (!result.Success) { Alert($"Error: {result.Message}", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(request)); } Alert($"Country Updated Successfully", NotificationType.success, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(RedirectToAction(nameof(Index))); } catch { Alert($"Error Occurred While processing the request", NotificationType.error, Int32.Parse(_appConfig.Value.NotificationDisplayTime)); return(View(request)); } }
public Country UpdateCountry([FromBody] Country country) { if (country != null) { var business = CountryBusiness.Instance; var request = new UpdateCountryRequest(this.Context); request.Country = country; country = business.UpdateCountry(request); } return(country); }
public Country UpdateCountry(UpdateCountryRequest request) { Country country = null; if (request != null && request.Country != null) { var dataAccess = new CountryDataAccess(request.Context); country = dataAccess.Update(request.Country); } return(country); }
public async Task <IActionResult> Put([FromRoute] int id, [FromBody] UpdateCountryRequest request) { var country = new Country { Id = id, Name = request.Name }; if (await _countryService.UpdateCountryAsync(country)) { return(Ok(new CountryResponse { Id = country.Id, Name = country.Name })); } return(NotFound()); }
public async Task <ServiceResponse <Country> > Update(Guid id, UpdateCountryRequest request) { try { var country = await _countryRepository.GetById(id); if (country == null) { return(new ServiceResponse <Country>($"The Requested resource could not be found")); } country.Name = request.Name; country.Description = request.Description; await _countryRepository.Update(country); return(new ServiceResponse <Country>(country)); } catch (Exception) { return(new ServiceResponse <Country>($"An Error Occured while Updating Country Resource")); } }
//[Authorize(Roles = "Admin")] public async Task <ActionResult <Country> > UpdateCountryById([FromBody] UpdateCountryRequest country, int id) { var updated = await _service.UpdateCountryByIdAsync(id, country); return(Ok(new { status = 200, data = updated, message = "Country was successfully updated!" })); }
//[Authorize(Roles = "Admin")] public async Task <ActionResult <Country> > CreateCountry([FromBody] UpdateCountryRequest country) { var created = await _service.CreateCountryAsync(country); return(Ok(new { status = 200, data = created, message = "Country was successfully created!" })); }