public IActionResult Register([FromBody] DeliveryModel deliveryModel) { // map dto to entity var delivery = _iMapper.Map <Delivery>(deliveryModel); try { // save var result = _iDeliveryService.Create(delivery, delivery.PostId, delivery.ResumeId); var count = 1; if (result != null) { return(Output(new DeliveryModel { DeliveryId = result.DeliveryId, PostId = result.PostId, ResumeId = result.ResumeId, DeliveryUpdateTime = result.DeliveryUpdateTime }, count)); } throw new Exception("创建失败!"); } catch (AppException ex) { // return error message if there was an exception return(BadRequest(new { message = ex.Message })); } }
public async Task <IActionResult> Post(DeliveryRequest request) { var serviceModel = _mapper.Map <DeliveryRecord>(request); serviceModel.State = DeliveryState.Created; var result = await _deliveryService.Create(serviceModel); return(result.Success ? Ok(_mapper.Map <DeliveryResponse>(result.Result)) : GenerateResultFromServiceResult(result)); }
public async Task <IActionResult> Create([FromBody] DeliveryDto deliveryDto) { try { if (deliveryDto == null) { throw new ArgumentNullException(nameof(deliveryDto)); } var createResult = await _deliveryService.Create(_executionContext, deliveryDto); return(Ok(createResult)); } catch (UnauthorizedException) { return(StatusCode(StatusCodes.Status401Unauthorized)); } catch (Exception e) { _logger.LogError("Error happened while Create", e); return(BadRequest()); } }
public override async Task <IActionResult> Create( [HttpTrigger(AuthorizationLevel.Function, "post", Route = "Delivery")] HttpRequest req, ILogger log) { try { log.LogInformation(""); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); DeliveryMV view = JsonConvert.DeserializeObject <DeliveryMV>(requestBody); var model = view.Adapt <Delivery>(); var deliveryID = await Task.Run(() => { return(deliveryService.Create(model)); }); view = model.Adapt <DeliveryMV>(); view.ID = deliveryID; return(new OkObjectResult(Task.FromResult(view))); } catch (Exception ex) { return(new BadRequestObjectResult(ex.Message)); } }
public IHttpActionResult Create(DeliveryCreate request) { _deliveryService.Create(request); return(Ok()); }