示例#1
0
        public async Task <ActionResult> Post([FromBody] AddOrderDto order)
        {
            order.Validate <AddOrderDtoValidator, AddOrderDto>();
            var orderResult = await _serviceFactory.OrderService.AddAsync(order.Number);

            return(Ok(orderResult));
        }
示例#2
0
        /* Add to DB actions */
        public string AddOrder(int carId, int workerId, int clientId, AddOrderDto addOrderDto)
        {
            if (!addOrderDto.Validate())
            {
                return("Validation error!");
            }

            var order  = _orderConverter.AddOrderDtoToOrder(addOrderDto);
            var car    = _carRepository.Get(carId);
            var worker = _workerRepository.Get(workerId);

            car.WorkerId = worker.Id;
            car.Worker   = worker;
            car.IsAway   = true;

            worker.Car = car;

            order.CarId    = carId;
            order.WorkerId = workerId;
            order.ClientId = clientId;
            order.Finished = false;
            order.Cost     = order.RentalTime * car.PricePerDay;
            _orderRepository.Add(order);

            return($"Order with id {order.Id} was succesfuly deleted");
        }
示例#3
0
        public async Task <IActionResult> AddOrder([FromBody] AddOrderDto dto)
        {
            if (dto?.ProductList == null)
            {
                return(BadRequest("参数不能为空"));
            }

            Uow.BeginTransaction();
            try
            {
                var orderHeader = new OrderHeader
                {
                    CreateTime = DateTime.UtcNow,
                    CustomerNo = dto.CustomerNo,
                    State      = 1,
                    OrderNo    = Guid.NewGuid().ToString("N")
                };

                await OrderHeaderRepository.InsertAsync(orderHeader);

                var orderDetailList = new List <OrderDetail>();
                //总消费金额
                var totalAmount = 0m;
                dto.ProductList.ForEach(it =>
                {
                    var orderDetail = new OrderDetail
                    {
                        OrderHeaderId = orderHeader.Id,
                        ProductNo     = it.ProductNo,
                        ProductName   = it.ProductName,
                        Quantity      = it.Quantity,
                        Price         = it.Price
                    };
                    orderDetailList.Add(orderDetail);

                    totalAmount += it.Quantity * it.Price;
                });

                await OrderDetailRepository.BatchInsertAsync(orderDetailList);

                //更新用户消费金额
                var success = await CustomerRepository.UpdateCustomerAmount(dto.CustomerNo, totalAmount);

                if (!success)
                {
                    Uow.RollBack();

                    return(BadRequest());
                }
            }
            catch (Exception e)
            {
                Uow.RollBack();
            }

            Uow.Commit();

            return(Ok());
        }
示例#4
0
 public Order AddOrderDtoToOrder(AddOrderDto addOrderDto)
 {
     return(new Order
     {
         OrderDate = addOrderDto.OrderDate,
         RentalTime = addOrderDto.RentalTime,
         DeliveryPlace = addOrderDto.DeliveryPlace
     });
 }
        public async Task AddAsync(AddOrderDto addOrder, CancellationToken ct = default)
        {
            _logger.LogInformation("Add order {@Order}", addOrder);

            ICollection <OrderGame> orderGames = addOrder.Games.Select(q => new OrderGame(q.OrderId, q.GameId)).ToList();

            CompletedOrder order = new CompletedOrder(addOrder.Id, addOrder.AccountId, addOrder.CreatedAt, orderGames);

            _unitOfWork.OrderRepository.Create(order);

            await _unitOfWork.SaveAsync(ct);
        }
示例#6
0
        public static void AddNewOrder(int worker, int car, int client, int rt, string dp, DateTime od)
        {
            var newOrder = new AddOrderDto()
            {
                DeliveryPlace = dp,
                RentalTime    = rt,
                OrderDate     = od,
            };

            DocumentService.AddOrder(car, worker, client, newOrder);
            LoadDataToWorkerListView(DocumentService.GetAllOrders());
        }
示例#7
0
        public async Task <OrderDto> AddOrderAsync(AddOrderDto addOrder)
        {
            var orderEntity = _unitOfWork.Orders.Add(_mapper.Map <AddOrderDto, Order>(addOrder));

            var bookOrders = addOrder.Carts.Select(
                x => new BookOrder
            {
                BookId = x.Book.Id, Order = orderEntity, Amount = x.Amount
            });

            _unitOfWork.BookOrders.AddRange(bookOrders);

            await _unitOfWork.CommitAsync();

            return(_mapper.Map <Order, OrderDto>(orderEntity));
        }
示例#8
0
        public async Task <GetOrderDto> AddAsync(AddOrderDto order, CancellationToken ct = default)
        {
            _logger.LogInformation("Add new order for account={AccountId}", order.AccountId);

            OrderBase currentOrder = await _unitOfWork.OrderRepository.GetCurrentOrderAsync(order.AccountId, ct);

            if (currentOrder != null)
            {
                _logger.LogInformation("User {AccountId} already has uncompleted order", order.AccountId);
                throw new AccountHasUncompletedOrderException();
            }

            OrderBase newOrder = new OrderBase(order.AccountId);

            _unitOfWork.OrderRepository.Create(newOrder);
            await _unitOfWork.SaveAsync(ct);

            return(_mapper.Map <GetOrderDto>(newOrder));
        }
示例#9
0
        public async Task <CreationState> AddOrder(AddOrderDto orderDto)
        {
            var creationState = new CreationState {
                IsCreatedSuccessfully = false, CreatedObjectId = null
            };

            var product = await _unitOfWork.ProductRepository.FindByIdAsync(orderDto.ProductId);

            if (orderDto.OrderQuantity <= product.ProductQuantity)
            {
                var newOrder = _mapper.Map <AddOrderDto, Orders>(orderDto);
                // if user choose chicken
                if (product.ProductCategory == ProductCategory.Chicken && product.KiloOfProduct >= orderDto.KiloOfOrder)
                {
                    newOrder.OrderPrice = (float)(newOrder.KiloOfOrder * product.ProductPrice);
                }
                else
                {
                    creationState.ErrorMessages.Add("Dismatch Kilo of order in kilo in product");
                }

                // if user choose Chick
                if (product.ProductCategory == ProductCategory.Chick && product.ProductQuantity >= newOrder.OrderQuantity)
                {
                    newOrder.OrderPrice = (float)(newOrder.OrderQuantity * product.ProductPrice);
                }
                else
                {
                    creationState.ErrorMessages.Add("Dismatch quantity of order in quantity in product");
                }
                await _unitOfWork.OrderRepository.CreateAsync(newOrder);

                creationState.IsCreatedSuccessfully = await _unitOfWork.SaveAsync() > 0;

                creationState.CreatedObjectId = newOrder.Id;
            }
            else
            {
                creationState.ErrorMessages.Add("Invaled quantity of order");
            }
            return(creationState);
        }
示例#10
0
        public async Task <IActionResult> AddOrder([FromBody] AddOrderDto addOrderDto)
        {
            try
            {
                var result = await _orderService.AddOrder(addOrderDto);

                if (result.IsCreatedSuccessfully)
                {
                    _logger.LogInformation("Adding New order");
                    return(Ok(result));
                }
                _logger.LogError(result.ErrorMessages.FirstOrDefault());
                return(BadRequest(result));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(BadRequest(ex.Message));
            }
        }
示例#11
0
文件: AddOrder.cs 项目: hiwamn/Mukta
        public ApiResult Execute(AddOrderDto dto)
        {
            ApiResult result = new ApiResult {
                Status = true, Message = Messages.Success,
            };
            var now = DateTime.Now.ToUnix();

            Order ord = new Order
            {
                PartyId       = dto.PartyId,
                StatusId      = Enums.EntityStatus.Deactive.ToInt(),
                CreatedAt     = now,
                InvoiceImages = dto.InvoiceImages?.Select(p => new OrderDocuments {
                    CreatedAt = now, DocumentId = p
                }).ToList(),
                DeliveryPeriod            = dto.DeliveryPeriod,
                Description               = dto.Description,
                Discount                  = dto.Discount,
                Insurance                 = dto.Insurance,
                ItemCode                  = dto.ItemCode,
                NetPrice                  = dto.NetPrice,
                PaymentTerms              = dto.PaymentTerms,
                PurchaseOrderValidityDate = dto.PurchaseOrderValidityDate,
                Quantity                  = dto.Quantity,
                RatePerUnit               = dto.RatePerUnit,
                SaleTax  = dto.SaleTax,
                SlNo     = unit.Order.GetMaxSlNo(),
                Days     = dto.Days,
                DayCount = dto.DayCount,
                Name     = dto.Name
            };

            unit.Order.Add(ord);
            unit.Complete();
            result.Object = Agent.ToJson(ord);
            return(result);
        }
示例#12
0
        public async Task <ServiceResponse <GetOrderDto> > AddOrder(AddOrderDto newOrder)
        {
            var private_ordernumber = GetOrderNumber();

            var _order = new mOrder
            {
                DateOrder   = Now(),
                ItemCount   = newOrder.ItemCount,
                Total       = newOrder.Total,
                Discount    = newOrder.Discount,
                Net         = newOrder.Net,
                CreateBy    = GetUsername(),
                CreateDate  = Now(),
                Status      = true,
                OrderNumber = private_ordernumber,
            };

            _dbContext.Orders.Add(_order);
            await _dbContext.SaveChangesAsync();

            var dto = _mapper.Map <GetOrderDto>(_order);

            return(ResponseResult.Success(dto));
        }
 public CreateOrderCommand(AddOrderDto order, int userId)
 {
     Order  = order;
     UserId = userId;
 }
示例#14
0
 public ActionResult <ApiResult> AddOrder([FromBody] AddOrderDto dto)
 {
     return(addOrder.Execute(dto));
 }
 public async Task <IActionResult> AddOrder(AddOrderDto newOrder)
 {
     return(Ok(await _orderService.AddOrder(newOrder)));
 }
示例#16
0
 public async Task AddOrderToRestaurant(AddOrderDto input)//add order to specific restaurant
 {
     string userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
     var    order  = Order.Create(input.Note, input.Place, input.RestaurantId, userId);
     await _orderRepo.AddAsync(order);
 }
示例#17
0
 public ActionResult Create(AddOrderDto newOrder, IFormCollection collection)
 {
     //var result = await _orderService.AddPost(newOrder);
     //return RedirectToAction(nameof(Details), new {detailsOrder = result});
 }
        protected override async Task <GetOrderDto> ExecuteAsync(CreateOrderCommand request, CancellationToken ct)
        {
            AddOrderDto orderDto = _mapper.Map <AddOrderDto>(request);

            return(await _orderService.AddAsync(orderDto, ct));
        }