Ejemplo n.º 1
0
        public void DeleteOrder(int orderId)
        {
            OrderEntity order = Database.OrdersRepository.GetOrderByID(orderId);

            if (order == null)
            {
                throw new ValidationException("Заказа с таким ключом не существует", "");
            }

            Database.OrdersRepository.Delete(order);

            Database.Save();
        }
Ejemplo n.º 2
0
        public async Task <OrderModel> CreateOrderAsync(List <CreateOrderItemModel> model)
        {
            if (!model.Any())
            {
                throw new ServerException(Constants.Errors.EMPTY_ORDER);
            }

            var user = await _userService.GetUserByIdAsync();

            var payment = new Payment
            {
                TransactionId = null
            };

            await _paymentRepository.CreateAsync(payment);

            decimal totalAmount = default;

            model.ForEach(item =>
            {
                totalAmount += item.Amount;
            });

            var order = new DataAccessLayer.Entities.Order
            {
                Description = null,
                Status      = StatusType.Unpaid,
                UserId      = user.Id,
                PaymentId   = payment.Id,
                TotalAmount = totalAmount
            };

            await _orderRepository.CreateAsync(order);

            await _orderItemService.CreateOrderItemAsync(order.Id, model);

            var orderModel = _mapper.Map <OrderModel>(order);

            return(orderModel);
        }