Ejemplo n.º 1
0
 public BMapRoutePlanningController(IAddressService addressService, IOrderservice orderService, IDeliveryStationService deliveryStationService, IDeliveryInfoService deliveryInfoService, ICourierService courierService)
 {
     _addressService         = addressService;
     _orderService           = orderService;
     _deliveryStationService = deliveryStationService;
     _deliveryInfoService    = deliveryInfoService;
     _courierService         = courierService;
 }
 public DeliveryInfosController(IDeliveryInfoService deliveryInfosService, IOrderService orderService,
                                IMapper mapper, IDeliveryManService deliveryManService, ICurrentLocationService currentLocationService)
 {
     this.deliveryInfosService = deliveryInfosService;
     this.orderService         = orderService;
     _mapper = mapper;
     this.deliveryManService     = deliveryManService;
     this.currentLocationService = currentLocationService;
 }
Ejemplo n.º 3
0
 public HomeController(ILogger <HomeController> logger, IOrderService orderService, IClientService clientService,
                       IDeliveryManService deliveryManService, IRatingService ratingService,
                       IDeliveryInfoService deliveryInfoService, IAdminService adminService)
 {
     _logger                  = logger;
     this.orderService        = orderService;
     this.clientService       = clientService;
     this.deliveryManService  = deliveryManService;
     this.ratingService       = ratingService;
     this.deliveryInfoService = deliveryInfoService;
     this.adminService        = adminService;
 }
Ejemplo n.º 4
0
 public DeliveryManController(IDeliveryManService deliveryManService, ILocationService locationService,
                              IDeliveryInfoService deliveryInfoService, ICurrentLocationService currentLocationService,
                              UserManager <IdentityUser> userManager, IRatingService ratingService,
                              IAdminService adminService)
 {
     this.deliveryManService     = deliveryManService;
     this.locationService        = locationService;
     this.deliveryInfoService    = deliveryInfoService;
     this.currentLocationService = currentLocationService;
     _userManager       = userManager;
     this.ratingService = ratingService;
     this.adminService  = adminService;
 }
Ejemplo n.º 5
0
 public OrderController(IClientService clientService, IOrderService orderService,
                        IProductOrderService productOrderService, IProductService productService,
                        ICartProductService cartProductService, IDeliveryInfoService deliveryInfoService,
                        IDeliveryManService deliveryManService, IRatingService ratingService, IMapper mapper,
                        IAdminService adminService, IEmailSenderService emailSenderService)
 {
     this.clientService       = clientService;
     this.orderService        = orderService;
     this.productOrderService = productOrderService;
     this.productService      = productService;
     this.cartProductService  = cartProductService;
     this.deliveryInfoService = deliveryInfoService;
     this.deliveryManService  = deliveryManService;
     this.ratingService       = ratingService;
     _mapper                 = mapper;
     this.adminService       = adminService;
     this.emailSenderService = emailSenderService;
 }
Ejemplo n.º 6
0
 public OrderController(IOrderService orderService,
                        IDeliveryManService deliveryManService,
                        IProductOrderService productOrderService,
                        IProductImageService productImageService, IDeliveryInfoService deliveryInfoService,
                        IClientService clientService, IEmailSenderService emailSenderService, IProductService productService,
                        ICurrentLocationService currentLocationService, IAdminService adminService,
                        IRazorViewToStringRenderer razorViewToStringRenderer)
 {
     this.orderService           = orderService;
     this.deliveryManService     = deliveryManService;
     this.productOrderService    = productOrderService;
     this.productImageService    = productImageService;
     this.deliveryInfoService    = deliveryInfoService;
     this.clientService          = clientService;
     this.emailSenderService     = emailSenderService;
     this.productService         = productService;
     this.currentLocationService = currentLocationService;
     this.adminService           = adminService;
     _razorViewToStringRenderer  = razorViewToStringRenderer;
 }
Ejemplo n.º 7
0
 public DeliveryInfosController(IDeliveryInfoService deliveryInfoService, IMapper mapper)
 {
     _deliveryInfoService = deliveryInfoService;
     _mapper = mapper;
 }
 public DeliveryInfoController(IDeliveryInfoService deliveryInfoService)
 {
     _deliveryInfoService = deliveryInfoService;
 }
        public BaseResponse <OrderHistoryAPIViewModel> AddOrderFromMobile(OrderAPIViewModel order)
        {
            using (TransactionScope scope =
                       new TransactionScope(TransactionScopeOption.Required,
                                            new TransactionOptions {
                IsolationLevel = IsolationLevel.RepeatableRead
            }))
            {
                try
                {
                    #region call service
                    DateTime             time                = DataService.Models.Utils.GetCurrentDateTime();
                    IStoreService        storeService        = DependencyUtils.Resolve <IStoreService>();
                    IDeliveryInfoService deliveryInfoService = DependencyUtils.Resolve <IDeliveryInfoService>();
                    IVoucherService      voucherService      = DependencyUtils.Resolve <IVoucherService>();
                    var orderService   = DependencyUtils.Resolve <IOrderService>();
                    var productService = DependencyUtils.Resolve <IProductService>();
                    #endregion

                    #region set default order
                    order.DeliveryStatus = (int)DeliveryStatus.New;
                    //order.OrderType = (int)OrderTypeEnum.Delivery;
                    order.OrderStatus = (int)OrderStatusEnum.New;
                    order.InvoiceID   = ConstantManager.PREFIX_MOBILE + "-" + order.StoreID + "-" + InvoiceCodeGenerator.GenerateInvoiceCode(); // truyền mã hóa don
                    order.SourceType  = (int)SourceTypeEnum.Mobile;
                    order.IsSync      = false;
                    int paymentType = order.PaymentType;
                    #endregion

                    #region check customer existed
                    var customer = new CustomerDomain().GetCustomerById(order.CustomerID.Value);
                    if (customer == null)
                    {
                        throw ApiException.Get(false, ConstantManager.MES_CHECK_CUSTOMERID_FAIL, ResultEnum.CustomerNotFound, HttpStatusCode.NotFound);
                    }
                    #endregion
                    #region check parent and child OrderDetail
                    foreach (var item in order.OrderDetails)
                    {
                        if (item.ParentId == 0)
                        {
                            item.ParentId = null;
                        }
                        if (item.ParentId != null && item.ParentId > -1)
                        {
                            var parentOrderDetail = order.OrderDetails.FirstOrDefault(od => od.TmpDetailId == item.ParentId);
                            if (parentOrderDetail != null)
                            {
                                var listExtra = productService.getProductExtraById(parentOrderDetail.ProductID);
                                var check     = listExtra.FirstOrDefault(e => e.ProductID == item.ProductID);
                                if (check == null)
                                {
                                    throw ApiException.Get(false, ConstantManager.MES_CHILD_ORDERDETAIL_WRONG, ResultEnum.ChildOrderDetailWrong, HttpStatusCode.BadRequest);
                                }
                            }
                            else
                            {
                                throw ApiException.Get(false, ConstantManager.MES_PARENT_ORDERDETAIL_NOTFOUND, ResultEnum.ParentOrderDetailNotFound, HttpStatusCode.BadRequest);
                            }
                        }
                    }
                    #endregion

                    #region calculate price of order detail and order
                    #region check voucher existed
                    if (!string.IsNullOrEmpty(order.VoucherCode))
                    {
                        var voucher = voucherService.GetVoucherIsNotUsedAndCode(order.VoucherCode);
                        if (voucher == null)
                        {
                            throw ApiException.Get(false, ConstantManager.MES_CREATE_ORDER_NOT_FOUND_VOUCHER, ResultEnum.VoucherNotFound, HttpStatusCode.NotFound);
                        }
                    }
                    #endregion
                    CalculateOrderPrice(order, time);
                    #endregion

                    #region Update Order Type info
                    switch (order.OrderType)
                    {
                    case (int)OrderTypeEnum.MobileDelivery:
                        var deliveryInfo = deliveryInfoService.GetDeliveryById(order.DeliveryInfoId);
                        if (deliveryInfo != null && deliveryInfo.CustomerId == customer.CustomerID)
                        {
                            order.Receiver        = deliveryInfo.CustomerName;
                            order.DeliveryAddress = deliveryInfo.Address;
                            order.DeliveryPhone   = deliveryInfo.Phone;
                        }
                        else
                        {
                            throw ApiException.Get(true, ConstantManager.MES_DELIVERYID_WRONG, ResultEnum.DeliveryNotFound, HttpStatusCode.OK);
                        }
                        break;

                    case (int)OrderTypeEnum.AtStore:
                        order.DeliveryAddress = OrderTypeEnum.AtStore.DisplayName();
                        order.Receiver        = customer.Name;
                        order.DeliveryPhone   = customer.Phone;
                        break;

                    case (int)OrderTypeEnum.MobileTakeAway:
                        order.DeliveryAddress = OrderTypeEnum.MobileTakeAway.DisplayName();
                        order.Receiver        = customer.Name;
                        order.DeliveryPhone   = customer.Phone;
                        break;

                    default:
                        if (string.IsNullOrEmpty(order.DeliveryAddress))
                        {
                            throw ApiException.Get(true, ConstantManager.MES_ORDERTYPE_NOTSUPPORT, ResultEnum.OrderTypeNotSupport, HttpStatusCode.OK);
                        }
                        break;
                    }

                    #endregion

                    //get CallCenter storeid
                    //var mobileStore = storeService.GetStoresByBrandIdAndType(order.BrandId, (int)StoreTypeEnum.MobileApp).FirstOrDefault();
                    //if (mobileStore != null)
                    //{
                    //    order.StoreID = mobileStore.ID;
                    //}

                    order.GroupPaymentStatus = 0; //Tam thoi chua xài
                    order.PaymentStatus      = (int)OrderPaymentStatusEnum.Finish;
                    customer.BrandId         = order.BrandId;


                    #region Update payment
                    new PaymentDomain().UpdatePayment(order, customer, time);
                    #endregion
                    if (order.Payments.Count <= 0)
                    {
                        throw ApiException.Get(true, ConstantManager.MES_PAYMENTTYPE_NOTSUPPORT, ResultEnum.PaymenTypeNotSupport, HttpStatusCode.OK);
                    }
                    var orderTest = order.ToEntity();
                    var rs        = orderService.CreateOrder(orderTest);



                    if (rs == false)
                    {
                        throw ApiException.Get(false, ConstantManager.MES_CREATE_ORDER_FAIL, ResultEnum.CreateFail, HttpStatusCode.InternalServerError);
                    }

                    #region Update voucher after used
                    CheckVoucherUsed(order.VoucherCode);
                    #endregion
                    scope.Complete();
                    scope.Dispose();
                    var orderFinal = orderService.GetOrderByRenId(orderTest.RentID);
                    orderFinal.PaymentType = paymentType;
                    return(BaseResponse <OrderHistoryAPIViewModel> .Get(true, ConstantManager.MES_CREATE_ORDER_SUCCESS, orderFinal, ResultEnum.Success));
                }
                catch (Exception e)
                {
                    scope.Dispose();
                    if (e is ApiException)
                    {
                        throw e;
                    }
                    else
                    {
                        throw ApiException.Get(false, ConstantManager.MES_CREATE_ORDER_FAIL, ResultEnum.CreateFail, HttpStatusCode.InternalServerError);
                    }
                }
            }
        }