/// <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); } }
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); } }
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); } }