public async Task <IActionResult> UpdatePie([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 pieToUpdate = await _pieService.GetPieById(pie.Id); if (pieToUpdate == null) { return(NotFound()); } await _pieService.UpdatePie(pie); return(NoContent()); //success }
public void UpdatePie(Pie pie) { try { if (pie == null || string.IsNullOrWhiteSpace(pie.PieName)) { throw new FaultException("Pie name is required"); } Pie pieToUpdate = _pieService.GetPieById(pie.Id); if (pieToUpdate != null) { _pieService.UpdatePie(pie); } else { throw new FaultException("Pie doesn't exist"); } } catch (Exception ex) { throw new FaultException("Something went wrong: " + ex.Message); } }
public void UpdatePie(Pie pie) { try { if (pie == null || string.IsNullOrWhiteSpace(pie.PieName)) { throw new SoapException("Pie name is required", SoapException.ClientFaultCode); } Pie pieToUpdate = _pieService.GetPieById(pie.Id); if (pieToUpdate != null) { _pieService.UpdatePie(pie); } else { throw new SoapException("Pie doesn't exist", SoapException.ClientFaultCode); } } catch (Exception ex) { throw new SoapException("Something went wrong", SoapException.ServerFaultCode, ex); } }