示例#1
0
        public string CreateOrder(Order order)
        {
            try
            {
                logger.Info("Start creating new order");
                var announcement = "thanh cong";
                var distributor  = _distributorRepository.Get(x => x.idDistributor == order.idDistributor);
                if (distributor != null)
                {
                    var contract = _distributorService.GetCurrentContract(order.idDistributor ?? 0);
                    if (contract != null)
                    {
                        if (contract.maxDebt > distributor.debt.GetValueOrDefault())
                        {
                            if (contract.minOrderTotalValue.GetValueOrDefault() <= order.Total.GetValueOrDefault())
                            {
                                _orderRepository.Add(order);
                                _unitOfWork.SaveChange();
                            }
                            else
                            {
                                announcement = "Tổng tiền của đơn đặt hàng thấp hơn mức quy định";
                                logger.Error("Error: Order Total is currently lower than acceptable amount");
                            }
                        }
                        else
                        {
                            announcement = "Nhà phân phối đã nợ quá số tiền cho phép";
                            logger.Error("Error: The distributor has too high debt");
                        }
                    }
                    else
                    {
                        announcement = "Nhà phân phối hiện không có bất cứ hợp đồng nào";
                        logger.Error("Error: The distributor doesn't have any contracts");
                    }
                }
                else
                {
                    announcement = "Nhà phân phối không tồn tại";
                    logger.Error("Error: The distributor doesn't exist");
                }
                logger.Info("Success: New order has been created successfully!");
                return(announcement);
            }
            catch (Exception ex)
            {
                logger.Info("Error: Encounter this error while creating new order: {0}", ex.Message);
                return("Không thể tạo đơn đặt hàng");

                throw;
            }
        }