Пример #1
0
        public async Task <ActionResult <OrderDto> > AddOrder(OrderDto order)
        {
            var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);

            try
            {
                var insertedOrder = await m_ordersService.AddAsync(order);

                var statusHelper = new OrderStatusHelper(m_orderStatusService);
                await statusHelper.AddOrderStatusAsync(insertedOrder.Id, order.OrderStatus);

                //Не используется т.к. работает Automapper
                var orderPositionHelper = new OrderPositionHelper(m_orderPositionService);
                await orderPositionHelper.AddOrderPositionAsync(insertedOrder.Id, order.OrderPosition);

                var target = await m_ordersService.GetAsync(insertedOrder.Id);


                transaction.Complete();

                return(CreatedAtAction(nameof(GetOrder), new { id = target.Id }, target));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
            finally
            {
                transaction.Dispose();
            }
        }
Пример #2
0
        public CartController
        (
            ICrudService <OrderDto, int> orderService,
            ICrudService <OrderPositionDto, int> orderPositionService,
            ICrudService <OrderStatusDto, int> orderStatusService
        )
        {
            m_ordersService        = orderService;
            m_orderPositionService = orderPositionService;
            m_orderStatusService   = orderStatusService;

            m_orderPositionHelper = new OrderPositionHelper(m_orderPositionService);
            m_orderStatusHelper   = new OrderStatusHelper(m_orderStatusService);
        }
Пример #3
0
        public async Task <ActionResult <OrderDto> > UpdateOrder(int id, OrderDto order)
        {
            if (id != order.Id)
            {
                return(BadRequest());
            }
            var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);

            try
            {
                await m_ordersService.UpdateAsync(order);

                //Не используется т.к. работает Automapper

                var orderPositionHelper = new OrderPositionHelper(m_orderPositionService);
                await orderPositionHelper.DeleteOrderPositionAsync(order.Id);

                await orderPositionHelper.AddOrderPositionAsync(order.Id, order.OrderPosition);

                var statusHelper = new OrderStatusHelper(m_orderStatusService);
                await statusHelper.DeleteOrderStatusAsync(order.Id);

                await statusHelper.AddOrderStatusAsync(order.Id, order.OrderStatus);

                var target = await m_ordersService.GetAsync(id);

                transaction.Complete();

                return(Ok(target));
            }
            catch (Exception ex)
            {
                return(StatusCode(500));
            }
            finally
            {
                transaction.Dispose();
            }
        }