Example #1
0
        public PartialViewResult Main()
        {
            if (HttpContext.User.Identity.IsAuthenticated)
            {
                //string[] roles = _userRepository.GetRolesForUser(HttpContext.User.Identity.Name);
                if (HttpContext.User.IsInRole("admin"))
                {
                    return(PartialView("MainAdmin"));
                }
                else
                {
                    Queue queue = _queueRepository.GetQueue(HttpContext.User.Identity.Name);

                    if (HttpContext.User.IsInRole("employee"))
                    {
                        return(PartialView("MainEmployee", queue));
                    }
                    else
                    {
                        if (queue == null || queue.Id == 0)
                        {
                            return(PartialView("Label"));
                        }
                        else
                        {
                            return(PartialView("MainClient", queue));
                        }
                    }
                }
            }
            else
            {
                return(PartialView("Label"));
            }
        }
Example #2
0
        public ActionResult LogOff()
        {
            Queue queue = _queueRepository.GetQueue(HttpContext.User.Identity.Name);

            int userId = _userRepository.LogOffUser(HttpContext.User.Identity.Name);

            var context = GlobalHost.ConnectionManager.GetHubContext <QueueHub>();

            bool isEmployee = HttpContext.User.IsInRole("employee");

            if (isEmployee)
            {
                context.Clients.All.changeClass("#id_" + userId, "employeeOffLink");

                string json = ListOperationsToJson(userId);

                context.Clients.All.changeCountEmployees(json);
            }
            ;

            if (queue != null && queue.Id > 0 && queue.StateClient != StatesClient.NoClient)
            {
                context.Clients.All.removeClientFromQueue(queue.Id);

                if (isEmployee)
                {
                    string connectionIdClient = _hub.GetConnectionIdByLogin(queue.Client.Login);
                    if (!string.IsNullOrEmpty(connectionIdClient))
                    {
                        context.Clients.Client(connectionIdClient).addMessageClient("Обслуживание завершено");
                    }
                    ;
                }
                else
                {
                    context.Clients.All.changeCountClients(queue.Operation.CountClients, queue.Operation.Id);

                    if (queue.Employee != null && queue.Employee.EmployeeId > 0)
                    {
                        string connectionIdEmployee = _hub.GetConnectionIdByLogin(queue.Employee.Login);
                        if (!string.IsNullOrEmpty(connectionIdEmployee))
                        {
                            context.Clients.Client(connectionIdEmployee).addMessageEmployee("Клиент покинул очередь");
                        }
                        ;
                    }
                }
            }
            ;

            FormsAuthentication.SignOut();

            return(RedirectToAction("Index", "Home"));
        }
Example #3
0
        protected void Session_End(object sender, EventArgs e)
        {
            IRepositoryUser  _userRepository  = DependencyResolver.Current.GetService <IRepositoryUser>();
            IRepositoryQueue _queueRepository = DependencyResolver.Current.GetService <IRepositoryQueue>();
            IQueueHub        _hub             = DependencyResolver.Current.GetService <IQueueHub>();

            Queue queue = _queueRepository.GetQueue(HttpContext.Current.User.Identity.Name);

            int userId = _userRepository.LogOffUser(HttpContext.Current.User.Identity.Name);

            var context = GlobalHost.ConnectionManager.GetHubContext <QueueHub>();

            bool isEmployee = HttpContext.Current.User.IsInRole("employee");

            if (isEmployee)
            {
                context.Clients.All.changeClass("#id_" + userId, "employeeOffLink");
            }
            ;

            if (queue != null && queue.Id > 0 && queue.StateClient != StatesClient.NoClient)
            {
                context.Clients.All.removeClientFromQueue(queue.Id);

                if (isEmployee)
                {
                    string connectionIdClient = _hub.GetConnectionIdByLogin(queue.Client.Login);
                    if (!string.IsNullOrEmpty(connectionIdClient))
                    {
                        context.Clients.Client(connectionIdClient).addMessageClient("Обслуживание завершено");
                    }
                    ;
                }
                else
                {
                    context.Clients.All.changeCountClients(queue.Operation.CountClients, queue.Operation.Id);

                    if (queue.Employee != null && queue.Employee.EmployeeId > 0)
                    {
                        string connectionIdEmployee = _hub.GetConnectionIdByLogin(queue.Employee.Login);
                        if (!string.IsNullOrEmpty(connectionIdEmployee))
                        {
                            context.Clients.Client(connectionIdEmployee).addMessageEmployee("Клиент покинул очередь");
                        }
                        ;
                    }
                }
            }
            ;

            FormsAuthentication.SignOut();
        }