Exemplo n.º 1
0
        public FineDlg(UndeliveredOrder undeliveredOrder) : this()
        {
            Entity.UndeliveredOrder = undeliveredOrder;
            var RouteList = RouteListItemRepository.GetRouteListItemForOrder(UoW, undeliveredOrder.OldOrder)?.RouteList;

            Entity.RouteList = RouteList;
        }
        public OrderDTO GetOrderDetailed2(string authKey, int orderId)
        {
#if DEBUG
            logger.Debug("GetOrderDetailed2 called with args:\nauthKey: {0}\norderId: {1}", authKey, orderId);
#endif

            try
            {
                if (!CheckAuth(authKey))
                {
                    return(null);
                }

                using (var orderUoW = UnitOfWorkFactory.CreateForRoot <Order>(orderId))
                {
                    if (orderUoW == null || orderUoW.Root == null)
                    {
                        return(null);
                    }
                    var routeListItem = RouteListItemRepository.GetRouteListItemForOrder(orderUoW, orderUoW.Root);
                    return(new OrderDTO(routeListItem));
                }
            }
            catch (Exception e)
            {
                logger.Error(e);
            }
            return(null);
        }
        public bool ChangeOrderStatus2(string authKey, int orderId, string status, string bottlesReturned)
        {
            logger.Debug("Change order status2:\n orderId: {0}\n status: {1}\n bottles: {2}", orderId, status, bottlesReturned);

            try {
                if (!CheckAuth(authKey))
                {
                    return(false);
                }

                using (var orderUoW = UnitOfWorkFactory.CreateForRoot <Order>(orderId, $"[ADS]v2 Изменение статуса заказа {orderId}")) {
                    if (orderUoW == null || orderUoW.Root == null)
                    {
                        return(false);
                    }

                    var routeListItem = RouteListItemRepository.GetRouteListItemForOrder(orderUoW, orderUoW.Root);
                    if (routeListItem == null)
                    {
                        return(false);
                    }

                    if (routeListItem.Status == RouteListItemStatus.Transfered)
                    {
                        logger.Error("Попытка переключить статус у переданного адреса. address_id = {0}", routeListItem.Id);
                        return(false);
                    }

                    switch (status)
                    {
                    case "EnRoute": routeListItem.UpdateStatus(orderUoW, RouteListItemStatus.EnRoute, CallTaskWorker); break;

                    case "Completed": routeListItem.UpdateStatus(orderUoW, RouteListItemStatus.Completed, CallTaskWorker); break;

                    case "Canceled": routeListItem.UpdateStatus(orderUoW, RouteListItemStatus.Canceled, CallTaskWorker); break;

                    case "Overdue": routeListItem.UpdateStatus(orderUoW, RouteListItemStatus.Overdue, CallTaskWorker); break;

                    default: return(false);
                    }

                    int bottles;
                    if (int.TryParse(bottlesReturned, out bottles))
                    {
                        routeListItem.DriverBottlesReturned = bottles;
                        logger.Debug("Changed! order status2:\n orderId: {0}\n status: {1}\n bottles: {2}", orderId, status, bottles);
                    }

                    orderUoW.Save(routeListItem);
                    orderUoW.Commit();
                    return(true);
                }
            }
            catch (Exception e) {
                logger.Error(e);
            }
            return(false);
        }
        public OrderDTO GetOrderDetailed(string authKey, int orderId)
        {
                        #if DEBUG
            logger.Debug("GetOrderDetailed called with args:\nauthKey: {0}\norderId: {1}", authKey, orderId);
                        #endif

            try
            {
                if (!CheckAuth(authKey))
                {
                    return(null);
                }

                using (var orderUoW = UnitOfWorkFactory.CreateForRoot <Order>(orderId, "[ADS]Детальная информация по заказу"))
                {
                    if (orderUoW == null || orderUoW.Root == null)
                    {
                        return(null);
                    }
                    var              routeListItem    = RouteListItemRepository.GetRouteListItemForOrder(orderUoW, orderUoW.Root);
                    OrderDTO         orderDTO         = new OrderDTO(routeListItem);
                    SmsPaymentStatus?smsPaymentStatus = OrderSingletonRepository.GetInstance().GetOrderPaymentStatus(orderUoW, orderUoW.Root.Id);
                    if (smsPaymentStatus == null)
                    {
                        orderDTO.PaymentStatus = PaymentStatus.None;
                    }
                    else
                    {
                        switch (smsPaymentStatus.Value)
                        {
                        case SmsPaymentStatus.WaitingForPayment:
                            orderDTO.PaymentStatus = PaymentStatus.WaitingForPayment;
                            break;

                        case SmsPaymentStatus.Paid:
                            orderDTO.PaymentStatus = PaymentStatus.Paid;
                            break;

                        case SmsPaymentStatus.Cancelled:
                            orderDTO.PaymentStatus = PaymentStatus.Cancelled;
                            break;
                        }
                    }

                    return(orderDTO);
                }
            }
            catch (Exception e)
            {
                logger.Error(e);
            }
            return(null);
        }
        public bool ChangeOrderStatus(string authKey, int orderId, string status, int?bottlesReturned)
        {
            try
            {
                if (!CheckAuth(authKey))
                {
                    return(false);
                }

                using (var orderUoW = UnitOfWorkFactory.CreateForRoot <Order>(orderId))
                {
                    if (orderUoW == null || orderUoW.Root == null)
                    {
                        return(false);
                    }

                    var routeListItem = RouteListItemRepository.GetRouteListItemForOrder(orderUoW, orderUoW.Root);
                    if (routeListItem == null)
                    {
                        return(false);
                    }

                    if (routeListItem.Status == RouteListItemStatus.Transfered)
                    {
                        logger.Error("Попытка переключить статус у переданного адреса. address_id = {0}", routeListItem.Id);
                        return(false);
                    }

                    switch (status)
                    {
                    case "EnRoute": routeListItem.UpdateStatus(orderUoW, RouteListItemStatus.EnRoute); break;

                    case "Completed": routeListItem.UpdateStatus(orderUoW, RouteListItemStatus.Completed); break;

                    case "Canceled": routeListItem.UpdateStatus(orderUoW, RouteListItemStatus.Canceled); break;

                    case "Overdue": routeListItem.UpdateStatus(orderUoW, RouteListItemStatus.Overdue); break;

                    default: return(false);
                    }
                    routeListItem.DriverBottlesReturned = bottlesReturned;

                    orderUoW.Save(routeListItem);
                    orderUoW.Commit();
                    return(true);
                }
            }
            catch (Exception e)
            {
                logger.Error(e);
            }
            return(false);
        }
Exemplo n.º 6
0
        protected void OnButtonAddFineClicked(object sender, EventArgs e)
        {
            if (undelivery.Id == 0)
            {
                if (QSOrmProject.CommonDialogs.SaveBeforeCreateSlaveEntity(undelivery.GetType(), typeof(Fine)))
                {
                    var saved = isSaved?.Invoke();
                    if (!saved.HasValue || !saved.Value)
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
            }

            FineDlg fineDlg;

            using (IUnitOfWork uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                fineDlg = new FineDlg(uow.GetById <UndeliveredOrder>(undelivery.Id));
            }

            MyTab.TabParent.OpenTab(
                DialogHelper.GenerateDialogHashName <Fine>(undelivery.Id),
                () => fineDlg
                );

            var address = new RouteListItemRepository().GetRouteListItemForOrder(UoW, undelivery.OldOrder);

            if (address != null)
            {
                fineDlg.Entity.AddAddress(address);
            }

            fineDlg.EntitySaved += (object sender2, QS.Tdi.EntitySavedEventArgs args) => {
                undelivery.Fines.Add(args.Entity as Fine);

                GetFines();
            };
        }
Exemplo n.º 7
0
        public static void StartService(IConfig serviceConfig, IConfig firebaseConfig, IDriverServiceParametersProvider parameters)
        {
            string serviceHostName;
            string servicePort;
            string serviceWebPort;
            string smsPaymentServiceHostName;
            string smsPaymentServicePort;

            string firebaseServerApiToken;
            string firebaseSenderId;

            try {
                serviceHostName           = serviceConfig.GetString("service_host_name");
                servicePort               = serviceConfig.GetString("service_port");
                serviceWebPort            = serviceConfig.GetString("service_web_port");
                smsPaymentServiceHostName = serviceConfig.GetString("payment_service_host_name");
                smsPaymentServicePort     = serviceConfig.GetString("payment_service_port");

                firebaseServerApiToken = firebaseConfig.GetString("firebase_server_api_token");
                firebaseSenderId       = firebaseConfig.GetString("firebase_sender_id");
            }
            catch (Exception ex) {
                logger.Fatal(ex, "Ошибка чтения конфигурационного файла.");
                throw;
            }

            logger.Info(String.Format("Запуск службы для водителей"));

            IDriverNotificator driverNotificator = new FirebaseCloudMessagingClient(firebaseServerApiToken, firebaseSenderId);

            ChannelFactory <ISmsPaymentService> smsPaymentServiceChannelFactory = new ChannelFactory <ISmsPaymentService>(
                new BasicHttpBinding(),
                string.Format("http://{0}:{1}/SmsPaymentService", smsPaymentServiceHostName, smsPaymentServicePort)
                );

            var wageParameterService = new WageParameterService(
                new WageCalculationRepository(), new BaseParametersProvider(new ParametersProvider()));

            var employeeRepository      = new EmployeeRepository();
            var routeListRepository     = new RouteListRepository(new StockRepository(), new BaseParametersProvider(new ParametersProvider()));
            var routeListItemRepository = new RouteListItemRepository();
            var trackRepository         = new TrackRepository();
            var orderRepository         = new OrderRepository();

            AndroidDriverServiceInstanceProvider androidDriverServiceInstanceProvider =
                new AndroidDriverServiceInstanceProvider(
                    wageParameterService, parameters, smsPaymentServiceChannelFactory, driverNotificator, employeeRepository,
                    routeListRepository, routeListItemRepository, trackRepository, orderRepository);

            ServiceHost ChatHost          = new ServiceHost(typeof(ChatService));
            ServiceHost AndroidDriverHost = new AndroidDriverServiceHost(androidDriverServiceInstanceProvider);

            ChatHost.AddServiceEndpoint(
                typeof(IChatService),
                new BasicHttpBinding(),
                String.Format("http://{0}:{1}/ChatService", serviceHostName, servicePort)
                );

            ServiceEndpoint webEndPoint = AndroidDriverHost.AddServiceEndpoint(
                typeof(IAndroidDriverServiceWeb),
                new WebHttpBinding(),
                String.Format("http://{0}:{1}/AndroidDriverServiceWeb", serviceHostName, serviceWebPort)
                );
            WebHttpBehavior httpBehavior = new WebHttpBehavior();

            webEndPoint.Behaviors.Add(httpBehavior);

            AndroidDriverHost.AddServiceEndpoint(
                typeof(IAndroidDriverService),
                new BasicHttpBinding(),
                String.Format("http://{0}:{1}/AndroidDriverService", serviceHostName, servicePort)
                );

#if DEBUG
            ChatHost.Description.Behaviors.Add(new PreFilter());
            AndroidDriverHost.Description.Behaviors.Add(new PreFilter());
#endif

            ChatHost.Open();
            AndroidDriverHost.Open();

            //Запускаем таймеры рутины
            orderRoutineTimer          = new System.Timers.Timer(120000);    //2 минуты
            orderRoutineTimer.Elapsed += OrderRoutineTimer_Elapsed;
            orderRoutineTimer.Start();
            trackRoutineTimer          = new System.Timers.Timer(30000);    //30 секунд
            trackRoutineTimer.Elapsed += TrackRoutineTimer_Elapsed;
            trackRoutineTimer.Start();

            logger.Info("Server started.");
        }