public async Task <IActionResult> DeleteConfirmed(Guid id) { if (id == Guid.Empty) { ModelState.AddModelError(string.Empty, "Unexpected error occurred: The ID was blank."); return(BadRequest(ModelState)); } var result = await _service.Delete(id); if (result == ActionMessages.Deleted) { return(RedirectToAction(nameof(Index), new { message = "The requested country was successfully removed." })); } else if (result == ActionMessages.NotFound) { return(RedirectToAction(nameof(Index), new { message = string.Empty, error = "The requested country could not be found. Please update your page and try again." })); } else { ModelState.AddModelError(string.Empty, "Unexpected error: The action failed."); return(BadRequest(ModelState)); } }
public override async Task <int> HandleCommand(DeleteCommand request, CancellationToken cancellationToken) { return(await countryRepository.Delete(DeleteBuild(new Country() { Id = request.CountryId }, request.LoginSession))); }
public async Task <IActionResult> DeleteCountry([FromRoute] Guid id) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var countryData = await _countryRepo.GetCountry(id); if (countryData == null) { return(NotFound()); } if (countryData.Protected == true) { ModelState.AddModelError("Error", "This record is a protected record. It can not be deleted"); return(BadRequest(ModelState)); } _countryRepo.Delete(countryData); await _unitOfWork.CompleteAsync(); return(Ok(id)); } catch (Exception ex) { ModelState.AddModelError("Error", "An error occured while performing this operation. There might be some records depending on this record"); return(BadRequest(ModelState)); } }
public void Delete(int id) { var entity = repository.GetById(id); repository.Delete(entity); Save(); }
public IActionResult DeleteCountry([FromQuery] int countryId) { var errorMessages = new List <string>(); try { var c = _countryRepository.FindById(countryId); if (c == null) { return(NotFound()); } var deletedCountry = _countryRepository.Delete(c.Id); if (deletedCountry == null) { errorMessages.Add("Error deleting country"); return(BadRequest(new { errors = errorMessages })); } return(Ok(new { deletedCountryId = deletedCountry.Id })); } catch (Exception ex) { errorMessages.Add(ex.Message); return(BadRequest(new { errors = errorMessages })); } }
public async Task <IActionResult> Delete(int id) { try { if (id < 1) { return(BadRequest()); } var isExists = await _countryRepository.isExists(id); if (!isExists) { return(NotFound()); } var country = await _countryRepository.FindById(id); var isSuccess = await _countryRepository.Delete(country); if (!isSuccess) { return(InternalError($"Delete operation failed")); } return(NoContent()); } catch (Exception e) { return(InternalError($"{e.Message} - {e.InnerException}")); } }
public IActionResult DeleteCountry(string countryName) { Country country = countryRepository.GetAll().FirstOrDefault(c => c.CountryName == countryName); countryRepository.Delete(country); return(Ok("success")); }
public void Delete(int id) { if (id == 0) { throw new ArgumentException("The id can't be zero."); } iCountryRepository.Delete(id); }
public void Delete(CountryViewModel model) { var item = _repository.FindById(model.Id); if (item != null) { _repository.Delete(item); } }
public IActionResult DeleteCountry(int countryId) { var result = _countryRepository.Delete(countryId); if (result == null) { return(BadRequest("Item not found")); } return(Ok("Deleted successfully")); }
public IActionResult DeleteCountry(long id) { Country a = Country_repo.Find(id); if (a == null) { return(NotFound()); } Country_repo.Delete(a); return(Ok()); }
public IActionResult Delete(int id) { var todelete = _repository.Get(id); if (todelete != null) { _repository.Delete(todelete); return(Helper.CheckResult(todelete, true)); } return(NotFound()); }
// GET: CountryController/Delete/5 public ActionResult Delete(int id) { var country = _countryRepository.FindById(id); var isSuccess = _countryRepository.Delete(country); if (!isSuccess) { return(BadRequest()); } return(RedirectToAction(nameof(Index))); }
public bool Delete(Guid id) { try { return(_repository.Delete(id)); } catch (Exception ex) { _logger.LogError("Exception while deleting country : {0} - {1} ", ex.StackTrace, ex.Message); throw ex; } }
/// <summary> /// Deletes a country /// </summary> /// <param name="country">Country</param> public virtual void DeleteCountry(Country country) { if (country == null) { throw new ArgumentNullException("country"); } _countryRepository.Delete(country); _cacheManager.GetCache(CACHE_NAME_COUNTRY).Clear(); //event notification //_eventPublisher.EntityDeleted(country); }
public ActionResult Delete(CountryDTO entity) { try { Country c = countryRepository.GetById(entity.CountryID); countryRepository.Delete(c); countryRepository.Save(); return(Json(entity, JsonRequestBehavior.DenyGet)); } catch (Exception e) { return(Json(false, JsonRequestBehavior.DenyGet)); } }
public ActionResult Delete(int id) { var countryFromRepository = _repository.Get(id); if (countryFromRepository == null) { return(NotFound()); } _repository.Delete(countryFromRepository); _repository.SaveChanges(); return(NoContent()); }
public async Task <IActionResult> Delete([FromRoute] int Id) { var countries = await _productDbContext.Countries.FindAsync(Id); if (countries != null) { await _countryRepository.Delete(countries); return(NoContent()); } else { return(NotFound()); } }
/// <summary> /// The Delete /// </summary> /// <param name="entity">The entity<see cref="Country"/></param> /// <returns>The <see cref="ServiceResult"/></returns> public ServiceResult Delete(Country entity) { try { _repository.Delete(entity); return(new ServiceResult(true)); } catch (Exception ex) { return(new ServiceResult(false) { Error = ex.ToString() }); } }
public IActionResult Delete(int id) { Country country = countryRepository.GetSingle(id); if (country == null) { return(new NotFoundResult()); } else { countryRepository.Delete(country); countryRepository.Commit(); return(new NoContentResult()); } }
public async Task <IActionResult> Delete(Guid id) { if (id == Guid.Empty || string.IsNullOrWhiteSpace(id.ToString())) { return(BadRequest()); } var result = await _service.Delete(id); if (result == false) { return(BadRequest("Something went wrong when trying to delete city. Please try again.")); } return(Ok(result)); }
public async Task <IActionResult> DeleteCountry(int?id) { if (!id.HasValue) { return(BadRequest("Id must be given")); } var deleted = await _countryRepository.Delete(id.Value); if (deleted) { return(Ok("Country deleted")); } return(NotFound("Country not found")); }
public IActionResult Delete(int Id) { CommonResponse <int> response = new CommonResponse <int>(); var result = _countryRepository.Delete(Id, this.loginUserId); if (result == 0) { response.status = Helper.failure_code; response.message = Message.countryDeletedError; } else { response.status = Helper.success_code; response.message = Message.countryDeleted; } return(Ok(response)); }
public bool DeleteCountry([FromBody] Contracts.DataModels.Country model) { try { Contracts.DataModels.Country country = _countryRepository.GetByAltId(model.AltId); if (country != null) { _countryRepository.Delete(country); _activityHelper.SaveActivity("Deleted Country - " + country.Name, "You have deleted country " + country.Name + " on " + DateTime.Now.ToString("ddd, dd MMM yyy HH:mm:ss"), model.CreatedBy); return(true); } } catch (Exception ex) { } return(false); }
// GET: Countries/Delete/5 public async Task <IActionResult> Delete(int id) { var quocgia = await _countryRepository.GetByIdAsync(id); if (quocgia == null) { return(NotFound()); } var result = _countryRepository.Delete(quocgia); if (result == null) { SetAlert("Xóa quốc gia không thành công", "error"); } else { SetAlert("Xóa quốc gia thành công", "success"); } return(RedirectToAction(nameof(Index))); }
public IHttpActionResult Delete([FromODataUri] int key) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Country country = countryRepository.GetById(key); if (country == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } countryRepository.Delete(country); //return Ok(); var response = Request.CreateResponse(HttpStatusCode.NoContent); return(ResponseMessage(response)); }
public bool Delete(long ID) { try { var reasonObj = GetCountry(ID); if (reasonObj != null) { reasonRepository.Delete(ID); } else { throw new Exception("Country Not Found."); } } catch (Exception ex) { throw new Exception(ex.Message); } return(true); }
public void Country_Repository_Create() { //Arrange Country c = new Country() { CountryName = "Test Country", CountryCode = "TC" }; //remove if exist before add again //var existCountry = objRepo.FindBy(a=>a.CountryCode =="TC"); //if (existCountry != null && existCountry.Count() > 0) objRepo.Delete(a => a.CountryCode == "TC"); //Act var result = objRepo.Add(c); objRepo.Save(); var lst = objRepo.GetAll().ToList(); //Assert // Assert.AreEqual(192, lst.Count); Assert.AreEqual("Test Country", lst.Last().CountryName); }
public JsonResult Delete(int id) { bool result = false; try { //Fetch contact from db var country = _countryRepository.GetById(id); if (country == null) { return(Json(result)); } _countryRepository.Delete(country); result = true; return(Json(result)); } catch (Exception) { return(Json(false)); } }
public async Task <IActionResult> Delete(int id) { try { var dbCountry = await _countryRepo.GetById(id); if (dbCountry == null) { return(BadRequest("No country exist with following Id")); } await _countryRepo.Delete(id); await _countryRepo.SaveAsync(); return(Ok()); } catch (Exception ex) { _logger.LogError(ex.Message); var exMsg = new HttpResponseMessage(HttpStatusCode.InternalServerError); throw new System.Web.Http.HttpResponseException(exMsg); } }