public bool CheckUserDocumentReadable(string userId, int documentId, bool receivedDocument)
        {
            var userDepartment = new UserDepartment();

            userDepartment = _departmentRepository.GetUserMainOrganization(userId);
            if (userDepartment != null)
            {
                string listSubDepartmentId = userDepartment.ListSubDepartmentId;
                int    departmentId        = userDepartment.DepartmentId;
                List <SPCheckUserDocumentReadable_Result> listCheckUserDocumentReadable = new List <SPCheckUserDocumentReadable_Result>();
                listCheckUserDocumentReadable = _entities.SPCheckUserDocumentReadable(userId, documentId, receivedDocument, departmentId, listSubDepartmentId).ToList();
                if (listCheckUserDocumentReadable.Count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        public List <SPGetTaskDocumentHistory_Result> GetTaskAssigneeDocumentHistory(int taskId, int documentId, string documentReceived)
        {
            List <SPGetTaskDocumentHistory_Result> result = new List <SPGetTaskDocumentHistory_Result>();

            List <SPGetTaskDocumentHistory_Result> listAssignee = _entities.SPGetTaskDocumentHistory(taskId, documentId, documentReceived).ToList();

            foreach (var item in listAssignee)
            {
                bool exist = false;
                foreach (var r in result)
                {
                    if (r.UserId == item.UserId)
                    {
                        exist = true;
                        break;
                    }
                }
                if (!exist)
                {
                    result.Add(item);
                }
            }
            string userId = "";
            int    count  = 0;

            foreach (var item in listAssignee)
            {
                if (item.UserId == item.CreatedBy)
                {
                    count++;
                }
                userId = item.CreatedBy;
            }
            if (count == 0)
            {
                bool            checkReceived             = documentReceived == "1" ? true : false;
                DocumentHistory history                   = _entities.DocumentHistories.FirstOrDefault(n => n.UserId == userId && n.DocumentId == documentId && n.ReceivedDocument == checkReceived);
                UserDepartment  userDepartment            = _departmentRepository.GetUserMainOrganization(userId);
                SPGetTaskDocumentHistory_Result createdBy = new SPGetTaskDocumentHistory_Result();

                if (history != null)
                {
                    createdBy.HistoryId  = history.Id;
                    createdBy.ViewDetail = true;
                    //createdBy.ViewOn = history.AttempOn;

                    createdBy.AttempOn    = history.AttempOn;
                    createdBy.Coprocessor = false;
                    createdBy.CreatedBy   = userId;
                    createdBy.CreatedOn   = DateTime.Now;
                    createdBy.Avatar      = userDepartment.Avatar;
                    createdBy.FullName    = userDepartment.FullName;
                    createdBy.Name        = userDepartment.FirstName;
                    createdBy.Order       = 1;
                    createdBy.Position    = userDepartment.Position;
                    createdBy.Assignee    = false;
                    createdBy.Supervisor  = false;
                    createdBy.TaskId      = taskId;
                    createdBy.UserId      = userId;
                }
                else
                {
                    createdBy.HistoryId  = null;
                    createdBy.ViewDetail = false;
                    // createdBy.ViewOn = null;

                    createdBy.AttempOn    = null;
                    createdBy.Coprocessor = false;
                    createdBy.CreatedBy   = userId;
                    createdBy.CreatedOn   = DateTime.Now;
                    createdBy.Avatar      = userDepartment.Avatar;
                    createdBy.FullName    = userDepartment.FullName;
                    createdBy.Name        = userDepartment.FirstName;
                    createdBy.Order       = 1;
                    createdBy.Position    = userDepartment.Position;
                    createdBy.Assignee    = false;
                    createdBy.Supervisor  = false;
                    createdBy.TaskId      = taskId;
                    createdBy.UserId      = userId;
                }
                result.Add(createdBy);
            }
            return(result);
        }