public ActionResult <DeliveryTypeDTO> Edit([FromBody] DeliveryTypeDTO deliveryTypeDTO) { try { if (!ModelState.IsValid) { return(UnprocessableEntity(ModelState)); } DeliveryType deliveryType = _mapper.Map <DeliveryType>(_deliveryTypeAppService.GetById(deliveryTypeDTO.Id, this.User)); if (deliveryType == null) { return(BadRequest()); } deliveryType.Description = deliveryTypeDTO.Description; deliveryType.DeliveryValue = deliveryTypeDTO.DeliveryValue; _deliveryTypeAppService.UpdateEntity(deliveryType); return(new ObjectResult(deliveryTypeDTO)); } catch (Exception ex) { return(BadRequest(ex)); } }
public ActionResult <DeliveryTypeDTO> GetById(long id) { try { DeliveryTypeDTO deliveryDTO = _mapper.Map <DeliveryTypeDTO>(_deliveryTypeAppService.GetById(id, this.User)); if (deliveryDTO == null) { return(NotFound()); } return(Ok(deliveryDTO)); } catch (Exception ex) { return(BadRequest(ex)); } }
public ActionResult <DeliveryTypeDTO> Create([FromBody] DeliveryTypeDTO deliveryTypeDTO) { try { if (!ModelState.IsValid) { return(UnprocessableEntity(ModelState)); } DeliveryType deliveryType = _mapper.Map <DeliveryType>(deliveryTypeDTO); if (_deliveryTypeAppService.CreateEntity(deliveryType) != null) { return(Created("/api/v1/deliverytype", HttpStatusCode.Created)); } return(BadRequest()); } catch (Exception ex) { return(BadRequest(ex)); } }