public IActionResult DeleteCountry(int countryId) { if (!_countryRepository.IsCountryExists(countryId)) { return(NotFound()); } Country countyToDelete = _countryRepository.GetCountry(countryId); ICollection <Author> authors = _countryRepository.GetAuthorsFromACountry(countryId); if (authors.Count() > 0) { ModelState.AddModelError("", "At first you have to delete this authors: \n" + authors.ToString() + $"Has not {countyToDelete.Name} delted"); return(StatusCode(409, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_countryRepository.DeleteCountry(countyToDelete)) { ModelState.AddModelError("", $"Somethink went wrong.Has not {countyToDelete.Name} delted"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult DeleteCountry(int countryId) { if (!_countryRepository.CountryExists(countryId)) { return(NotFound()); } //if the country is used by atleast one author, DB will restict the deletion, but we want to display an error to the user var countrytoDelete = _countryRepository.GetCountry(countryId); if (_countryRepository.GetAuthorsFromCountry(countryId).Count > 0) { ModelState.AddModelError("", $"Country {countrytoDelete.Name} cannot be deleted because it is used by atleast one author"); return(StatusCode(409, ModelState)); //Coflict } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_countryRepository.DeleteCountry(countrytoDelete)) { ModelState.AddModelError("", $"Sonething went wrong deleting {countrytoDelete.Name}"); return(StatusCode(500, ModelState)); //Server error } return(NoContent()); }
public IActionResult DeleteCountry(int countryId) { if (!_countryRepository.CountryExists(countryId)) { return(BadRequest()); } var countryToDelete = _countryRepository.GetCountry(countryId); if (_countryRepository.isDuplicateCountryName(countryId, countryToDelete.Name)) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest()); } if (!_countryRepository.DeleteCountry(countryToDelete)) { return(BadRequest(ModelState)); } else { return(Ok()); } }
public IActionResult DeleteCountry(int countryId) { //if (deletedCountryInfo == null) // return BadRequest(ModelState); if (!_countriesRepository.CountryExist(countryId)) { return(NotFound($"the country with the Id {countryId}, can not be found.")); } var countryToDelete = _countriesRepository.GetCountry(countryId); //if (countryId != deletedCountryInfo.Id) // return BadRequest(ModelState); if (_countriesRepository.GetAuthorsOfACountry(countryId).Count() > 0) { ModelState.AddModelError("", $"Sorry the country {countryToDelete.Name}, can not be deleted because there are at least 1 author from it."); return(StatusCode(409, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_countriesRepository.DeleteCountry(countryToDelete)) { ModelState.AddModelError("", $"Something went wrong deleting {countryToDelete.Name}."); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult DeleteCountry(int countryId) { if (!_countryRepository.CountryExists(countryId)) { return(NotFound()); } var countryToDelete = _countryRepository.GetCountry(countryId); if (_countryRepository.GetAuthorsFromACountry(countryId).Count() > 0) { ModelState.AddModelError("", $"Country {countryToDelete.Name} cannot be deleted BC it's used at least on author."); return(StatusCode(409, ModelState)); // 409 conflict. } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_countryRepository.DeleteCountry(countryToDelete)) { ModelState.AddModelError("", $"Something went wrong deleteing {countryToDelete.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult DeleteCountry(int countryId) { //Validation //check country exist in database if (_countryRepository.CountryExist(countryId)) { return(NotFound()); } var countryToDelete = _countryRepository.GetCountry(countryId); //since Author is foreighn key and has many many relationship with country . We need to check if //author in the requested country by checking the countryId if (_countryRepository.GetAuthorsFromACountry(countryId).Count > 0) { ModelState.AddModelError("", $"Country {countryToDelete.Name}" + "Can not deleted it is used by at least one Authors"); return(StatusCode(409, ModelState)); } //check if model exist if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //check if item is Deleted or not. If not then through error code 500 if (_countryRepository.DeleteCountry(countryToDelete)) { ModelState.AddModelError("", $"Something went wrong updating {countryToDelete.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public Country DeleteCountry(Guid id) { Country country = _countryRepository.GetCountryById(id); country.Deleted = true; return(_countryRepository.DeleteCountry(country)); }
// We don't need to pass in a country object, because we are not sending any country Info, we just want to grab the country and delete it public IActionResult DeleteCountry(int countryId) { // Make sure that the country that the user wants to delete actually exists in the database if (!_countryRepository.CountryExists(countryId)) { return(NotFound()); } var countryToDelete = _countryRepository.GetCountry(countryId); // Verify if an author is associated to that country, then we don't want to delete the country if (_countryRepository.GetAuthorsFromACountry(countryId).Count > 0) { ModelState.AddModelError("", $"Country {countryToDelete.Name} " + "cannot be deleted because it is used by at least one author"); // Return a 409, which is Conflict because of the foreign Key return(StatusCode(409, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // If we reach that point, we can try deleting the Country if (!_countryRepository.DeleteCountry(countryToDelete)) { // If there is somehow an error, return an 500 error ModelState.AddModelError("", $"Something went wrong deleting {countryToDelete.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult DeleteCountry(int countryId) { if (!countryRepository.CountryExists(countryId)) { return(NotFound()); } var countryToDelete = countryRepository.GetCountry(countryId); if (countryRepository.GetAuthorsFromACountry(countryId).Count() > 0) { ModelState.AddModelError("", $"Country {countryToDelete.Name}" + " cannot be deleted because at least one author is from that country"); return(StatusCode(409, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!countryRepository.DeleteCountry(countryToDelete)) { ModelState.AddModelError("", $"Something went wrong deleting {countryToDelete.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
[ProducesResponseType(409)] //Conflict public IActionResult DeleteCountry(int countryId) { if (!_countryRepository.CountryExists(countryId)) { return(NotFound()); } var countryToDelete = _countryRepository.GetCountry(countryId); //check if there are any authors from this country. If there is one then we cannot delete the country if (_countryRepository.GetAuthorsFromACountry(countryId).Count > 0) { ModelState.AddModelError("", $"Country {countryToDelete.Name} cannot be deleted because it is used by at least one author"); return(StatusCode(409, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_countryRepository.DeleteCountry(countryToDelete)) { ModelState.AddModelError("", $"Something went wrong deleting {countryToDelete.Name} "); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult DeleteCountry(int countryId) { if (!_countryRepository.CountryExists(countryId)) { return(NotFound()); } var countryToDelete = _countryRepository.GetCountry(countryId); if (_countryRepository.GetRecipesFromCountry(countryId).Count > 0) { ModelState.AddModelError("", $"Country {countryToDelete.Name} cannot be deleted because at least one recipe is linked to it"); return(StatusCode(409, ModelState)); //409 = conflict } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_countryRepository.DeleteCountry(countryToDelete)) { ModelState.AddModelError("", $"Something went wrong deleting {countryToDelete.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult DeleteCountry(int countryId) { if (!_countryRepository.CountryExists(countryId)) { return(NotFound()); } var countryToDelete = _countryRepository.GetCountry(countryId); var casesNumber = _countryRepository.GetCasesFromACountry(countryId).Count(); if (casesNumber > 0) { ModelState.AddModelError("", $"Country {countryToDelete.Name} " + "cannot be deleted because it has" + casesNumber + "case/s"); return(StatusCode(409, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_countryRepository.DeleteCountry(countryToDelete)) { ModelState.AddModelError("", $"Something went wrong deleting {countryToDelete.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult OnPost(string code) { if (Country != null) { repo.DeleteCountry(code); } return(RedirectToPage("IndexCountry")); }
public IActionResult Delete(int id) { Country abs = _CountryRepository.GetCountryById(id); if (abs == null) { return(NotFound()); } _CountryRepository.DeleteCountry(abs); return(RedirectToAction("index")); }
public async Task <ActionResult> Delete(int id) { if (await _countryRepository.DeleteCountry(id)) { return(NoContent()); } else { return(NotFound()); } }
public List <CountryModel> DeleteCountry(CountryModel aCountryModel) { _countryRepository.DeleteCountry(aCountryModel.ID); BaseViewModel model = new BaseViewModel(); model.CurrentCulture = aCountryModel.CurrentCulture; model.CurrentUserID = aCountryModel.CurrentUserID; List <CountryModel> countries = GetAllCountryList(model); return(countries); }
public IActionResult DeleteCountry(int id) { var country = _countryRepository.FindCountryById(id); if (country == null) { return(NotFound()); } _countryRepository.DeleteCountry(country); return(Ok()); }
public ActionResult Countries() { var url = Request.Url.Segments.Last(); var result = _validationService.CheckUrlHaveValueAndReturn(url); if (result > 0) { _countryRepository.DeleteCountry(result); } ViewBag.countries = _countryRepository.GetCountry(); return(View()); }
public void DeleteCountry(CountryDTO dto) { try { log.Debug(CountryDTO.FormatCountryDTO(dto)); R_Country t = CountryDTO.ConvertDTOtoEntity(dto); // delete Repository.DeleteCountry(t); dto.IsDeleted = t.IsDeleted; log.Debug("result: 'success'"); } catch (System.Exception e) { // error log.Error(e.ToString()); throw; } }
public IHttpActionResult DeleteCountry(int id) { Country country = countriesRepository.GetCountryByID(id); if (country == null) { return(NotFound()); } countriesRepository.DeleteCountry(id); countriesRepository.Save(); return(Ok(country)); }
public async Task <IActionResult> DeleteCountry(int id) { var country = await _countryRepository.GetCountryByIdAsync(id); if (country == null) { return(NotFound()); } _countryRepository.DeleteCountry(country); if (!await _unitOfWork.SaveAsync()) { return(StatusCode(500, $"删除时,id为{id}的数据出错")); } return(NoContent()); }
public IActionResult DeleteCountry(int id) { if (!countryRepo.CountryExists(id)) { return(NotFound()); } var countryObj = countryRepo.GetCountry(id); if (!countryRepo.DeleteCountry(countryObj)) { ModelState.AddModelError("", $"Doslo je do greske u izmjeni {countryObj.CountryName}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public async Task <IActionResult> Delete(Guid id) { var country = await countryRepository.GetCountryById(id); if (country == null) { return(NotFound()); } await countryRepository.DeleteCountry(country); if (!await unitOfWork.SaveAsync()) { return(StatusCode(500)); } return(NoContent()); }
public async Task <IActionResult> DeleteCountry(int id) { var country = await _countryRepository.GetCountryByIdAsync(id); if (country == null) { return(NotFound()); } _countryRepository.DeleteCountry(country); if (!await _unitOfWork.SaveAsync()) { throw new Exception($"Deleting country {id} failed when saving."); } return(NoContent()); }
public void DeleteCountry(Guid countryId) { List <PersonalUser> persUsers = _personalUserRepository.GetUsersWithCountry(countryId); if (persUsers.Count > 0) { throw new ReferentialConstraintViolationException("Value of country is referenced in another table"); } List <CorporationUser> corpUsers = _corporationUserRepository.GetUsersWithCountry(countryId); if (corpUsers.Count > 0) { throw new ReferentialConstraintViolationException("Value of country is referenced in another table"); } _countryRepository.DeleteCountry(countryId); _countryRepository.SaveChanges(); }
public IActionResult DeleteCountry(int id) { if (id == 0) { return(BadRequest()); } var countryToDelete = _countryRepository.GetCountryById(id); if (countryToDelete == null) { return(NotFound()); } _countryRepository.DeleteCountry(id); return(NoContent());//success }
public HttpResponseMessage Delete([FromBody] Models.country country) { try { //int con_id = int.Parse(country_id); bool updatCountry = countryRepository.DeleteCountry(country.country_id); var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "success", msg = "Country Delete Successfully." }, formatter)); } catch (Exception ex) { var formatter = RequestFormat.JsonFormaterString(); return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation { output = "error", msg = ex.ToString() }, formatter)); } }
public IActionResult DeleteCountry(int countryId) { if (!_countryRepository.CountryExist(countryId)) { return(NotFound()); } var country = _countryRepository.GetCountry(countryId); //if (_countryRepository.GetAuthorsFromCountry(countryId).Count()>0) //{ // ModelState.AddModelError("", $"something went wrong {country.Name} "); // return StatusCode(500, ModelState); //} if (!_countryRepository.DeleteCountry(country)) { ModelState.AddModelError("", $"country{country.Name} fail to delete"); return(StatusCode(422, ModelState)); } return(NoContent()); }
public IActionResult DeleteCountry(int countryId) { if (!countryRepository.CountryExists(countryId)) { return(NotFound()); } var deleteContry = countryRepository.GetCountry(countryId); if (countryRepository.GetDirectorsFromCountry(countryId).Count > 0) { ModelState.AddModelError("", "Country can not be deleted as One or More directors are still connnected"); return(StatusCode(409, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!countryRepository.DeleteCountry(deleteContry)) { ModelState.AddModelError("", $"Something went wrong, please try again"); } return(NoContent()); }
public IActionResult DeleteCountry(int countryId) { if (!_countryRepository.CountryExists(countryId)) { return(NotFound()); } var countryToDelete = _countryRepository.GetCountry(countryId); if (_countryRepository.GetAuthorsFromCountry(countryId).Count() > 0) { ModelState.AddModelError("", $"Country {countryToDelete.Name} can not be deleted. It has authors associated with it"); return(StatusCode(409, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_countryRepository.DeleteCountry(countryToDelete)) { ModelState.AddModelError("", $"There is some error occur while deleting country {countryToDelete.Name}."); return(StatusCode(500, ModelState)); } return(NoContent()); }