コード例 #1
0
ファイル: AjaxUI.aspx.cs プロジェクト: apxlee/SAP
 public static List<UI.RequestBlade> GetRequests(ViewIndex view, UI.Search search)
 {
     return UI.GetRequestBlades(view, search);
 }
コード例 #2
0
ファイル: Database.cs プロジェクト: apxlee/SAP
        public static List<UI.RequestBlade> GetRequests(ViewIndex view, UI.Search search)
        {
            try
            {
                string userId = SnapSession.CurrentUser.LoginId;
                string condition = "";
                var requestList = new List<UI.RequestBlade>();
                DateTime closedDateLimit = new DateTime();
                closedDateLimit = DateTime.Now.AddDays(-30);
                string dateTime = closedDateLimit.Year + "," + closedDateLimit.Month + "," + closedDateLimit.Day;
                string closedString = string.Format("statusEnum=={0}&&lastModifiedDate >= DateTime({1})", (int)RequestState.Closed, dateTime); ;
                string openString = string.Format("statusEnum=={0}||statusEnum=={1}||statusEnum=={2}", (int)RequestState.Open, (int)RequestState.Pending, (int)RequestState.Change_Requested);
                string requestCondition = string.Format("({0})||({1})",openString,closedString);

                using (var db = new SNAPDatabaseDataContext())
                {
                    switch (view)
                    {
                        case ViewIndex.my_approvals:
                            string groupNames = "";
                            foreach(string group in SnapSession.CurrentUser.MemberOf)
                            {
                                if (group != ""){groupNames += "userId==\"" + group + "\"||";}
                            }
                            groupNames = groupNames.Substring(0, groupNames.Length - 2);
                            string actorCondition = string.Format("(userId==\"{0}\"||({1}&&isGroup==true))",userId,groupNames);
                            List<int> workflowIds = (from r in db.SNAP_Requests.Where(requestCondition)
                                                     join w in db.SNAP_Workflows on r.pkId equals w.requestId
                                                     join ws in db.SNAP_Workflow_States on w.pkId equals ws.workflowId
                                                     join a in db.SNAP_Actors.Where(actorCondition) on w.actorId equals a.pkId
                                                     group ws by new { ws.workflowId } into grp
                                                     select grp.Max(s => s.pkId)).ToList();
                            var approvals = from r in db.SNAP_Requests
                                            join w in db.SNAP_Workflows on r.pkId equals w.requestId
                                            join ws in db.SNAP_Workflow_States on w.pkId equals ws.workflowId
                                            where workflowIds.Contains(ws.pkId)
                                            orderby r.lastModifiedDate descending
                                            select new
                                            {
                                                DisplayName = r.userDisplayName,
                                                RequestStatus = r.statusEnum,
                                                LastModified = r.lastModifiedDate,
                                                RequestId = r.pkId,
                                                WorkflowStatus = ws.workflowStatusEnum
                                            };
                            if (approvals != null)
                            {
                                foreach (var request in approvals)
                                {
                                    UI.RequestBlade newRequest = new UI.RequestBlade();
                                    newRequest.DisplayName = request.DisplayName.StripTitleFromUserName();
                                    newRequest.RequestStatus = Convert.ToString((RequestState)Enum.Parse(typeof(RequestState), request.RequestStatus.ToString())).StripUnderscore();
                                    newRequest.WorkflowStatus = request.WorkflowStatus.ToString();
                                    newRequest.LastModified = WebUtilities.TestAndConvertDate(request.LastModified.ToString());
                                    newRequest.RequestId = request.RequestId.ToString();
                                    requestList.Add(newRequest);
                                }
                            }
                            break;
                        case ViewIndex.my_requests:
                            condition = string.Format("(userId==\"{0}\"||submittedBy==\"{0}\")", userId);
                            var requests = db.SNAP_Requests.
                                Where(condition + "&&(" + requestCondition + ")").
                                OrderByDescending(r => r.lastModifiedDate).ToList();

                            if (requests != null)
                            {
                                foreach (var request in requests)
                                {
                                    UI.RequestBlade my_requests = new UI.RequestBlade();
                                    my_requests.DisplayName = request.userDisplayName.StripTitleFromUserName();
                                    my_requests.RequestStatus = Convert.ToString((RequestState)Enum.Parse(typeof(RequestState), request.statusEnum.ToString())).StripUnderscore();
                                    my_requests.WorkflowStatus = String.Empty;
                                    my_requests.LastModified = WebUtilities.TestAndConvertDate(request.lastModifiedDate.ToString());
                                    my_requests.RequestId = request.pkId.ToString();
                                    requestList.Add(my_requests);
                                }
                            }
                            break;
                        case ViewIndex.access_team:
                            var accessRequests = db.SNAP_Requests.
                                Where(requestCondition).
                                OrderByDescending(r => r.lastModifiedDate).ToList();

                            if (accessRequests != null)
                            {
                                foreach (var request in accessRequests)
                                {
                                    UI.RequestBlade access_team = new UI.RequestBlade();
                                    access_team.DisplayName = request.userDisplayName.StripTitleFromUserName();
                                    access_team.RequestStatus = Convert.ToString((RequestState)Enum.Parse(typeof(RequestState), request.statusEnum.ToString())).StripUnderscore();
                                    access_team.WorkflowStatus = String.Empty;
                                    access_team.LastModified = WebUtilities.TestAndConvertDate(request.lastModifiedDate.ToString());
                                    access_team.RequestId = request.pkId.ToString();
                                    requestList.Add(access_team);
                                }
                            }
                        break;
                        case ViewIndex.search:
                            string primaryCondition = "";
                            string rangeCondition = "";
                            List<object> values = new List<object>();
                            int valCount = 0;
                            if (search.Primary != string.Empty)
                            {
                                primaryCondition = "(pkId.ToString()==@0 or userId==@0 or userDisplayName.Contains(@0) or submittedBy==@0)";
                                values.Add((object)search.Primary);
                                condition = primaryCondition;
                            }
                            if (search.RangeStart != string.Empty)
                            {
                                DateTime rangeStart = Convert.ToDateTime(search.RangeStart);
                                if (search.RangeEnd != string.Empty)
                                {
                                    valCount = values.Count();
                                    DateTime rangeEnd = Convert.ToDateTime(search.RangeEnd);
                                    rangeCondition = "(createdDate>=@" + valCount.ToString() + " and createdDate<@" + (valCount + 1).ToString() + ")";
                                    values.Add((object)rangeStart);
                                    values.Add((object)rangeEnd.AddDays(1));
                                }
                                else
                                {
                                    valCount = values.Count();
                                    rangeCondition = "(createdDate>=@" + valCount.ToString() + ")";
                                    values.Add((object)rangeStart);
                                }
                                if (condition != string.Empty) { condition += " and " + rangeCondition; }
                                else { condition = rangeCondition; }
                            }

                            if (condition == string.Empty)
                            {
                                condition = "pkid>@0";
                                values.Add(0);
                            }
                            object[] objs = values.ToArray();
                            var searchResults = db.SNAP_Requests.
                                    Where(condition, objs).
                                    OrderByDescending(r => r.lastModifiedDate).ToList();

                            if (searchResults != null)
                            {
                                foreach (var request in searchResults)
                                {
                                    if (RequestContainsContents(search.Contents,request.pkId))
                                    {
                                        UI.RequestBlade search_request = new UI.RequestBlade();
                                        search_request.DisplayName = request.userDisplayName.StripTitleFromUserName();
                                        search_request.RequestStatus = Convert.ToString((RequestState)Enum.Parse(typeof(RequestState), request.statusEnum.ToString())).StripUnderscore();
                                        search_request.WorkflowStatus = String.Empty;
                                        search_request.LastModified = WebUtilities.TestAndConvertDate(request.lastModifiedDate.ToString());
                                        search_request.RequestId = request.pkId.ToString();
                                        requestList.Add(search_request);
                                    }
                                }
                            }
                        break;
                    }
                    return requestList;
                }
            }
            catch (Exception ex)
            {
                Logger.Error("GetRequests \r\nMessage: " + ex.Message + "\r\nStackTrace: " + ex.StackTrace);
                return null;
            }
        }