Esempio n. 1
0
        /// <summary>
        /// The change to delivery
        /// Author: ThanhDT
        /// Created date: 8/12/2020 8:56 AM
        /// </summary>
        /// <param name="order">The order.</param>
        private int ChangeOrderToDelivery(Entities.Order order)
        {
            int result;

            try
            {
                result = orderDal.ChangeToDelivery(order);
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(0);
            }
            return(result);
        }
Esempio n. 2
0
        public ErrorCodes ProcessCallAhamove(int orderId, string user)
        {
            try
            {
                var order = _orderDal.GetById(orderId);
                if (order != null && order.order_id > 0)
                {
                    // validate
                    if (order.status != OrderStatusEnum.KitchenDone.GetHashCode() || order.order_type != OrderTypeEnum.Delivery.GetHashCode())
                    {
                        return(ErrorCodes.StatusError);
                    }

                    if (order.delivery_status > 0 && order.delivery_status != DeliveryStatus.CallAnotherShipping.GetHashCode())
                    {
                        return(ErrorCodes.AhamoveExistError);
                    }

                    PathInfo kitchenPath = new PathInfo {
                        Address = StaticVariable.Kitchen1Address
                    };
                    PathInfo customerPath = new PathInfo {
                        Address = order.delivery_address, Name = order.customer_name, Mobile = order.customer_phone
                    };
                    var orderDetails  = _orderDetailDal.GetByOrderId(order.order_id);
                    var orderResponse = AhaMoveApi.CreateOrder(kitchenPath, customerPath, orderDetails.ToList());
                    if (orderResponse != null)
                    {
                        var orderInfo = new Entities.Order
                        {
                            order_id = order.order_id,
                            //status = (short)OrderStatusEnum.Delivering,
                            delivery_status        = (short)DeliveryStatus.Idle,
                            delivery_order_id      = orderResponse.order_id,
                            delivery_price         = orderResponse.order.total_pay,
                            delivery_estimate_time = orderResponse.order.duration,
                            reason_note            = "ChangeToDelivery"
                        };
                        var result = _orderDal.ChangeToDelivery(orderInfo);
                        if (result != 1)
                        {
                            Logger.ErrorLog("[ChangeToDelivery] Error save Delivery with OrderId: " + order.order_id);
                            return(ErrorCodes.BusinessError);
                        }
                        else
                        {
                            // ok thì bắn vào order history
                            _orderHistoryBo.Insert(new OrderHistory
                            {
                                change_log      = "ChangeToDelivery",
                                created_by      = user,
                                order_id        = orderId,
                                delivery_status = (short)DeliveryStatus.Idle
                            });

                            Logger.WriteLog(Logger.LogType.Info, "[ChangeToDelivery] SUCCESS save Delivery with OrderId: " + order.order_id);
                            return(ErrorCodes.Success);
                        }
                    }
                    else
                    {
                        Logger.ErrorLog("[ChangeToDelivery] Error change DeliveryStatus to ApiError with orderId: " + order.order_id);
                        return(ErrorCodes.AhamoveError);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
                return(ErrorCodes.Exception);
            }

            return(ErrorCodes.BusinessError);
        }