public async Task <ActionResult> PostCart([FromBody] OrderDto order)
        {
            var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);

            try
            {
                order.OrderTime   = DateTime.Now;
                order.OrderStatus = new List <OrderStatusDto>
                {
                    new OrderStatusDto {
                        StatusId = 2, Time = DateTime.Now
                    }
                };


                var insertedOrder = await m_ordersService.AddAsync(order);

                await m_orderPositionHelper.AddOrderPositionAsync(insertedOrder.Id, order.OrderPosition);

                await m_orderStatusHelper.AddOrderStatusAsync(insertedOrder.Id, order.OrderStatus);


                transaction.Complete();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
            finally
            {
                transaction.Dispose();
            }
        }
        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();
            }
        }
        public async Task <IActionResult> AddAsync(UserModel model)
        {
            var result = await _service.AddAsync(_mapper.Map <User>(model));

            if (result == default || result.Id == default)
            {
                return(BadRequest());
            }

            return(CreatedAtAction(nameof(GetByIdAsync), new { id = result.Id },
                                   _mapper.Map <UserModel>(result)));
        }
        public async Task <ActionResult <OrderStatusDto> > Add([FromBody] OrderStatusDto orderStatus)
        {
            try
            {
                var insertedOrderStatus = await orderStatusService.AddAsync(orderStatus);

                return(CreatedAtAction(nameof(Get), new { id = insertedOrderStatus.Id }, insertedOrderStatus));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
        public async Task <ActionResult <IngredientDto> > Add([FromBody] IngredientDto ingredient)
        {
            try
            {
                var insertedIngredient = await ingredientService.AddAsync(ingredient);

                return(CreatedAtAction(nameof(Get), new { id = insertedIngredient.Id }, insertedIngredient));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e));
            }
        }
 public async Task AddOrderStatusAsync(int orderId, IEnumerable <OrderStatusDto> orderStatusDtos)
 {
     foreach (var item in orderStatusDtos)
     {
         var status = new OrderStatusDto
         {
             OrderId  = orderId,
             Time     = item.Time,
             StatusId = item.StatusId
         };
         await orderStatusService.AddAsync(status);
     }
 }
        public async Task <ActionResult <CategoryDto> > Add([FromBody] CategoryDto category)
        {
            try
            {
                var insertedCategory = await categoryService.AddAsync(category);

                return(CreatedAtAction(nameof(Get), new { id = insertedCategory.Id }, insertedCategory));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e));
            }
        }
        public async Task AddIngredientsAsync(int productId, IEnumerable <IngredientDto> ingredients)
        {
            foreach (var ingredient in ingredients)
            {
                var productIngredient = new ProductIngredientDto
                {
                    IngredientId = ingredient.Id,
                    ProductId    = productId
                };

                await m_productIngredientService.AddAsync(productIngredient);
            }
        }
Beispiel #9
0
        public async Task <ActionResult <StudentDto> > AddAsync(StudentDto dto)
        {
            var validator = new DefaultStudentValidator(_studentValidationService);
            var entry     = await Student.BuildAsync(validator, dto.SexId, dto.Firstname, dto.Middlename, dto.Lastname, dto.Callsign);

            if (entry.HasErrors)
            {
                return(BadRequest(entry.ErrorsStrings));
            }

            entry = await _studentCrudService.AddAsync(entry);

            return(Ok(entry));
        }
Beispiel #10
0
        public async Task <ActionResult <GroupDto> > AddAsync(GroupDto dto)
        {
            var validator = new DefaultGroupValidator();
            var entry     = Group.Build(validator, dto.Name);

            if (entry.HasErrors)
            {
                return(BadRequest(entry.ErrorsStrings));
            }

            entry = await _groupCrudService.AddAsync(entry);

            return(Ok(entry.ToDto()));
        }
Beispiel #11
0
        public async Task AddOrderPositionAsync(int orderId, IEnumerable <OrderPositionDto> orderPositionDtos)
        {
            foreach (var item in orderPositionDtos)
            {
                var position = new OrderPositionDto
                {
                    OrderId   = orderId,
                    Amount    = item.Amount,
                    ProductId = item.ProductId
                };


                await orderPositionService.AddAsync(position);
            }
        }
Beispiel #12
0
        public TeamMutations(ICrudService <Team> teamService, ILogger <TeamMutations> logger)
        {
            FieldAsync <ActionResponseViewModel>(
                "create",
                "Add a new team",
                new QueryArguments(new QueryArgument <TeamCreateViewModel> {
                Name = "team"
            }),
                async context =>
            {
                try
                {
                    var model = context.GetArgument <Team>("team");
                    return(await teamService.AddAsync(model));
                }
                catch (Exception ex)
                {
                    logger.LogCritical(ex.Message, ex);
                    return(ActionResponse.ServerError());
                }
            }).AuthorizeWith(UserPermission.Team.ToString());

            FieldAsync <ActionResponseViewModel>(
                "update",
                "Update team",
                new QueryArguments(new QueryArgument <TeamUpdateViewModel> {
                Name = "team"
            }),
                async context =>
            {
                try
                {
                    var model = context.GetArgument <Dictionary <string, object> >("team");
                    return(await teamService.UpdateAsync(model));
                }
                catch (Exception ex)
                {
                    logger.LogCritical(ex.Message, ex);
                    return(ActionResponse.ServerError());
                }
            }).AuthorizeWith(UserPermission.Team.ToString());
        }
        public CaptainMutations(ICrudService <Captain> captainService, ILogger <CaptainMutations> logger)
        {
            FieldAsync <ActionResponseViewModel>(
                "create",
                "Add a new captain to the fleet",
                new QueryArguments(new QueryArgument <CaptainCreateViewModel> {
                Name = "captain"
            }),
                async context =>
            {
                try
                {
                    var model = context.GetArgument <Captain>("captain");
                    return(await captainService.AddAsync(model));
                }
                catch (Exception ex)
                {
                    logger.LogCritical(ex.Message, ex);
                    return(ActionResponse.ServerError());
                }
            }).AuthorizeWith(UserPermission.Captain.ToString());

            FieldAsync <ActionResponseViewModel>(
                "update",
                "Update captain",
                new QueryArguments(new QueryArgument <CaptainUpdateViewModel> {
                Name = "captain"
            }),
                async context =>
            {
                try
                {
                    var model = context.GetArgument <Dictionary <string, object> >("captain");
                    return(await captainService.UpdateAsync(model));
                }
                catch (Exception ex)
                {
                    logger.LogCritical(ex.Message, ex);
                    return(ActionResponse.ServerError());
                }
            }).AuthorizeWith(UserPermission.Captain.ToString());
        }
 public ExplorationMutations(ICrudService <Exploration> explorationService, ILogger <ExplorationMutations> logger)
 {
     FieldAsync <ActionResponseViewModel>(
         "create",
         "Add a new exploration to the fleet",
         new QueryArguments(new QueryArgument <ExplorationCreateViewModel> {
         Name = "exploration"
     }),
         async context =>
     {
         try
         {
             var model = context.GetArgument <Exploration>("exploration");
             return(await explorationService.AddAsync(model));
         }
         catch (Exception ex)
         {
             logger.LogCritical(ex.Message, ex);
             return(ActionResponse.ServerError());
         }
     }).AuthorizeWith(UserPermission.Exploration.ToString());
 }
        public async Task <ActionResult <ProductDto> > PostProduct(ProductDto product)
        {
            var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);

            try
            {
                var insertedProduct = await m_productsService.AddAsync(product);


                var productsHelper = new ProductIngredientHelper(m_productIngredientService);
                await productsHelper.AddIngredientsAsync(insertedProduct.Id, product.Ingredients);


                var targetProduct = await m_productsService.GetAsync(insertedProduct.Id);



                transaction.Complete();


                return(CreatedAtAction
                       (
                           nameof(GetProduct),
                           new { id = targetProduct.Id },
                           targetProduct
                       ));
            }
            catch (Exception ex)
            {
                return(StatusCode(500));
            }
            finally
            {
                transaction.Dispose();
            }
        }
Beispiel #16
0
 public async Task HandleAsync(AddEntityCommand <TEntity> command, CancellationToken cancellationToken = default)
 {
     await _crudService.AddAsync(command.Entity);
 }