public void AddPie(Pie pie) { try { if (pie == null || string.IsNullOrWhiteSpace(pie.PieName)) { throw new SoapException("Pie name is required", SoapException.ClientFaultCode); } _pieService.AddPie(pie); } catch (Exception ex) { throw new SoapException("Something went wrong", SoapException.ServerFaultCode, ex); } }
public void AddPie(Pie pie) { try { if (pie == null || string.IsNullOrWhiteSpace(pie.PieName)) { throw new FaultException("Pie name is required"); } _pieService.AddPie(pie); } catch (Exception ex) { throw new FaultException("Something went wrong: " + ex.Message); } }
public async Task <IActionResult> AddPie([FromBody] Pie pie) { if (pie == null) { return(BadRequest()); } if (pie.PieName == string.Empty) { ModelState.AddModelError("Pie name", "The pie name shouldn't be empty"); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createdPie = await _pieService.AddPie(pie); return(Created("pie", createdPie)); }