public static void AssertIsNotEmpty(string value, string message) { if (string.IsNullOrWhiteSpace(value)) { throw new OperationResultException(OperationResult.Alert("Ops!", message, NoteType.warning)); } }
public void Validate(City city) { if (_cityRepository.Exists(city)) { throw new OperationResultException(OperationResult.Alert("Error", "This city already exists.", NoteType.warning)); } }
public IActionResult Get(string id) { try { var city = _service.GetCityById(id); return(Ok(city)); } catch (OperationResultException ex) { return(Json(ex.result)); } catch (Exception ex) { return(Json(OperationResult.Alert("Ops", ex.Message, NoteType.danger))); } }
public IActionResult Get() { try { var cities = _service.ListAllCities(); return(Ok(cities)); } catch (OperationResultException ex) { return(Json(ex.result)); } catch (Exception ex) { return(Json(OperationResult.Alert("Ops", ex.Message, NoteType.danger))); } }
public IActionResult Delete(string id) { try { _service.RemoveCity(id); _unitOfWork.Commit(); return(Ok(OperationResult.Success)); } catch (OperationResultException ex) { return(Json(ex.result)); } catch (Exception ex) { return(Json(OperationResult.Alert("Ops", ex.Message, NoteType.danger))); } }
public IActionResult Post([FromBody] City city) { try { _service.SaveCity(city); _unitOfWork.Commit(); return(Ok(OperationResult.Success)); } catch (OperationResultException ex) { return(Json(ex.result)); } catch (Exception ex) { return(Json(OperationResult.Alert("Ops", ex.Message, NoteType.danger))); } }