Esempio n. 1
0
        public bool SendMessageToDriver(int senderId, int recipientId, string message)
        {
            try
            {
                using (var senderUoW = UnitOfWorkFactory.CreateForRoot <Employee>(senderId, $"[CS]Отправка сообщения водителю {recipientId}"))
                {
                    var recipient = senderUoW.GetById <Employee>(recipientId);

                    var chat = ChatRepository.GetChatForDriver(senderUoW, recipient);
                    if (chat == null)
                    {
                        chat          = new ChatClass();
                        chat.ChatType = ChatType.DriverAndLogists;
                        chat.Driver   = recipient;
                    }

                    ChatMessage chatMessage = new ChatMessage();
                    chatMessage.Chat     = chat;
                    chatMessage.DateTime = DateTime.Now;
                    chatMessage.Message  = message;
                    chatMessage.Sender   = senderUoW.Root;

                    chat.Messages.Add(chatMessage);
                    senderUoW.Save(chat);
                    senderUoW.Commit();

                    FCMHelper.SendMessage(recipient.AndroidToken, senderUoW.Root.ShortName, message);
                    return(true);
                }
            } catch (Exception e) {
                logger.Error(e);
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Sends the server notification to driver.
        /// ВНИМАНИЕ!!! Делает коммит UoW.
        /// </summary>
        public static bool SendServerNotificationToDriver(IUnitOfWork uow, Employee driver, string message, string androidNotification)
        {
            try {
                if (driver == null)
                {
                    return(false);
                }

                var chat = ChatRepository.GetChatForDriver(uow, driver);
                if (chat == null)
                {
                    chat          = new ChatClass();
                    chat.ChatType = ChatType.DriverAndLogists;
                    chat.Driver   = driver;
                }

                ChatMessage chatMessage = new ChatMessage();
                chatMessage.Chat                 = chat;
                chatMessage.DateTime             = DateTime.Now;
                chatMessage.Message              = message;
                chatMessage.IsServerNotification = true;
                chatMessage.IsAutoCeated         = true;

                chat.Messages.Add(chatMessage);
                uow.Save(chat);
                uow.Commit();

                FCMHelper.SendOrderStatusChangeMessage(driver.AndroidToken, UserNameOfServer, androidNotification);
                return(true);
            } catch (Exception e) {
                logger.Error(e);
                return(false);
            }
        }
Esempio n. 3
0
        public bool SendMessageToLogistician(string authKey, string message)
        {
            try {
                using (var uow = UnitOfWorkFactory.CreateWithoutRoot($"[CS]Отправка сообщения логисту"))
                {
                    var driver = EmployeeRepository.GetDriverByAuthKey(uow, authKey);
                    if (driver == null)
                    {
                        return(false);
                    }

                    var chat = ChatRepository.GetChatForDriver(uow, driver);
                    if (chat == null)
                    {
                        chat          = new ChatClass();
                        chat.ChatType = ChatType.DriverAndLogists;
                        chat.Driver   = driver;
                    }

                    ChatMessage chatMessage = new ChatMessage();
                    chatMessage.Chat     = chat;
                    chatMessage.DateTime = DateTime.Now;
                    chatMessage.Message  = message;
                    chatMessage.Sender   = driver;

                    chat.Messages.Add(chatMessage);
                    uow.Save(chat);
                    uow.Commit();
                    return(true);
                }
            } catch (Exception e) {
                logger.Error(e);
                return(false);
            }
        }
Esempio n. 4
0
        public bool SendDeliveryScheduleNotificationToDriver(int senderId, int routeListItemId)
        {
            try {
                using (var senderUoW = UnitOfWorkFactory.CreateForRoot <Employee>(senderId, $"[CS]Отправка сообщения о изменении времени заказа"))
                {
                    var routeListItem = senderUoW.GetById <RouteListItem>(routeListItemId);
                    var driver        = routeListItem.RouteList.Driver;

                    if (driver == null)
                    {
                        return(false);
                    }

                    var chat = ChatRepository.GetChatForDriver(senderUoW, driver);
                    if (chat == null)
                    {
                        chat          = new ChatClass();
                        chat.ChatType = ChatType.DriverAndLogists;
                        chat.Driver   = driver;
                    }

                    ChatMessage chatMessage = new ChatMessage();
                    chatMessage.Chat         = chat;
                    chatMessage.DateTime     = DateTime.Now;
                    chatMessage.IsAutoCeated = true;
                    chatMessage.Message      = String.Format("У заказа №{0} из маршрутного листа №{1} было изменено время доставки на \"{2}\".",
                                                             routeListItem.Order.Id,
                                                             routeListItem.RouteList.Id,
                                                             routeListItem.Order.DeliverySchedule.DeliveryTime);
                    chatMessage.Sender = senderUoW.Root;

                    chat.Messages.Add(chatMessage);
                    senderUoW.Save(chat);
                    senderUoW.Commit();
                    var message = String.Format("Изменение времени доставки заказа №{0}", routeListItem.Order.Id);

                    FCMHelper.SendOrderDeliveryScheduleChangeMessage(driver.AndroidToken, senderUoW.Root.ShortName, message);
                    return(true);
                }
            } catch (Exception e) {
                logger.Error(e);
                return(false);
            }
        }
Esempio n. 5
0
        public bool SendOrderStatusNotificationToDriver(int senderId, int routeListItemId)
        {
            try {
                using (var senderUoW = UnitOfWorkFactory.CreateForRoot <Employee>(senderId))
                {
                    var routeListItem = senderUoW.GetById <RouteListItem>(routeListItemId);
                    var driver        = routeListItem.RouteList.Driver;

                    if (driver == null)
                    {
                        return(false);
                    }

                    var chat = ChatRepository.GetChatForDriver(senderUoW, driver);
                    if (chat == null)
                    {
                        chat          = new ChatClass();
                        chat.ChatType = ChatType.DriverAndLogists;
                        chat.Driver   = driver;
                    }

                    ChatMessage chatMessage = new ChatMessage();
                    chatMessage.Chat         = chat;
                    chatMessage.DateTime     = DateTime.Now;
                    chatMessage.IsAutoCeated = true;
                    chatMessage.Message      = String.Format("Заказ №{0} из маршрутного листа №{1} был переведен в статус \"{2}\".",
                                                             routeListItem.Order.Id,
                                                             routeListItem.RouteList.Id,
                                                             routeListItem.Status.GetEnumTitle());
                    chatMessage.Sender = senderUoW.Root;

                    chat.Messages.Add(chatMessage);
                    senderUoW.Save(chat);
                    senderUoW.Commit();
                    var message = String.Format("Изменение статуса заказа №{0}", routeListItem.Order.Id);

                    FCMHelper.SendOrderStatusChangeMessage(driver.AndroidToken, senderUoW.Root.ShortName, message);
                    return(true);
                }
            } catch (Exception e) {
                logger.Error(e);
                return(false);
            }
        }