コード例 #1
0
        public async Task PlaceOrder(CreateCurbsideOrder orderToBePlaced)
        {
            var response = await CurbsideMapper.PlaceOrder(orderToBePlaced);

            await TheChannel.AddCurbsideOrder(new CurbsideChannelRequest { OrderId = response.Id, ClientId = Context.ConnectionId });

            await Clients.Caller.SendAsync("OrderPlaced", Mapper.Map <CurbsideOrder>(response));
        }
コード例 #2
0
        public async Task <ActionResult> PlaceOrder([FromBody] CreateCurbisdeOrder orderToPlace)
        {
            //validate the model (return 400 if bad)
            CurbsideOrder response = await _curbsideMapper.PlaceOrder(orderToPlace);

            // this should be wrapped in a try catch and if fails remove it from the database etc.
            await _channel.AddCurbsideOrder(new CurbsideChannelRequest { OrderId = response.Id });

            return(Ok(response));
        }
コード例 #3
0
        public async Task <ActionResult> PlaceOrder([FromBody] CreateCurbsideOrder orderToPlace)
        {
            // 1. Validate It (bad? return 400)
            // 2. Save it to the database - (e.g. do domain stuff)
            // 3. Return
            //      201 Created
            //      Location Header with the location of the new resource
            //      A copy of the entity they would get if they did a GET to the location
            CurbsideOrder response = await CurbsideMapper.PlaceOrder(orderToPlace);

            await TheChannel.AddCurbsideOrder(new CurbsideChannelRequest { OrderId = response.Id });

            // this could possibly throw..
            await TheHub.Clients.All.SendAsync("ApiOrderPlaced", response);

            return(Ok(response));
        }