Exemplo n.º 1
0
        protected void OnButtonOkClicked(object sender, EventArgs e)
        {
            var currentEmployee = EmployeeRepository.GetEmployeeForCurrentUser(UoW);
            var service         = new ChannelFactory <IChatService>(
                new BasicHttpBinding(),
                ChatMain.ChatServiceUrl).CreateChannel();

            var  accessToLogisticChat = ServicesConfig.CommonServices.CurrentPermissionService.ValidatePresetPermission("logistican");
            var  unreadedMessages     = ChatMessageRepository.GetUnreadedChatMessages(UoW, currentEmployee, accessToLogisticChat);
            bool needCommit           = false;

            foreach (var recipient in Recipients)
            {
                service.SendMessageToDriver(
                    currentEmployee.Id,
                    recipient.Id,
                    textviewMessage.Buffer.Text
                    );
                var unreaded = unreadedMessages.FirstOrDefault(x => x.EmployeeId == recipient.Id);
                if (unreaded == null)
                {
                    var chat = ChatRepository.GetChatForDriver(UoW, recipient);
                    if (chat != null)
                    {
                        chat.UpdateLastReadedTime(currentEmployee);
                        UoW.Save(chat);
                        needCommit = true;
                    }
                }
                if (needCommit)
                {
                    UoW.Commit();
                }
            }
        }