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