public ActionResult Dashboard() { if (BL.CurrentUser.Instance != null && BL.CurrentUser.Instance.VerifiedUser.UserId != Guid.Empty) { if (Service == null) { Service = BL.OrganizationUtility.GetCRMService(); } Session["Uname"] = BL.CurrentUser.Instance.VerifiedUser.FirstName + " " + BL.CurrentUser.Instance.VerifiedUser.LastName; ViewBag.Uname = BL.CurrentUser.Instance.VerifiedUser.UserName; BL.NotesData Model = new BL.NotesData() { lstPortalUser = null, lstAssignedPortalUser = null, lstDataRow = null, lstHeaderColumn = null }; Guid DocumentId = new Guid(); EntityCollection Col = PortalRepository.GetNameWiseDocumentId("new_documentmanagementsystem", Service, BL.CurrentUser.Instance.VerifiedUser.UserId, BL.CurrentUser.Instance.VerifiedUser.Documenttyp); if (Col != null && Col.Entities.Count > 0) { foreach (Entity enty in Col.Entities) { DocumentId = new Guid(enty.Attributes["new_documentmanagementsystemid"].ToString()); } } Model.IncidentId = DocumentId; //BL.DashboardData CounterData = PortalRepository.GetCounterDocumentNotesData("annotation", Service, Model.IncidentId, BL.CurrentUser.Instance.VerifiedUser.LastName); BL.DashboardData DashData = new BL.DashboardData(); //DashData.Approved = CounterData.Approved; // DashData.Reject = CounterData.Reject; // DashData.Pending = CounterData.Pending; ViewBag.LiDashboard = "class=active"; ViewBag.LiGetAllCasesForIncident = "class="; ViewBag.LiCreateCases = "class="; ViewBag.LiPassword = "******"; return(View(DashData)); // Service = BL.CRMUtility.GetCRMService(); //List<BL.Activity> lstActivity = PortalUserRepository.GetAllActivity(Service, BL.CurrentUser.Instance.VerifiedUser.UserId, Guid.Empty); } else { return(RedirectToAction("Login")); } }
public static BL.DashboardData GetCounterDocumentNotesData(string EntityName, IOrganizationService _service, Guid Id, string Search, string UserType, string ApprovalStatus, string PortalUser, DateTime StartDate, DateTime EndDate) { List <BL.NotesData> lst = new List <BL.NotesData>(); Entity ConfigEntity = null; EntityCollection Cols = null; if (UserType == "125970000") { QueryExpression QueryShared = new QueryExpression("mhl_portalnoteshared"); QueryShared.ColumnSet = new ColumnSet(true); QueryShared.Criteria.AddCondition(new ConditionExpression("mhl_portaluser", ConditionOperator.Equal, BL.CurrentUser.Instance.VerifiedUser.UserId)); EntityCollection ColsShared = _service.RetrieveMultiple(QueryShared); var SharedDocument = ColsShared.Entities.Select(x => x.Attributes["mhl_documentnotesid"]).ToArray(); if (SharedDocument.Length > 0) { QueryExpression Query = new QueryExpression(EntityName); Query.ColumnSet = new ColumnSet(new[] { "subject", "notetext", "objectid", "annotationid", "createdby", "createdon", "filename", "documentbody", "mimetype" }); FilterExpression filter = new FilterExpression(LogicalOperator.And); FilterExpression filter1 = new FilterExpression(LogicalOperator.And); filter1.Conditions.Add(new ConditionExpression("annotationid", ConditionOperator.In, ColsShared.Entities.Select(x => x.Attributes["mhl_documentnotesid"]).ToArray())); if (Id != Guid.Empty) { filter1.Conditions.Add(new ConditionExpression("objectid", ConditionOperator.Equal, Id)); } else { QueryExpression query = new QueryExpression("new_documentmanagementsystem"); query.ColumnSet = new ColumnSet(true); EntityCollection Col = _service.RetrieveMultiple(query); if (Col != null && Col.Entities.Count > 0) { filter1.Conditions.Add(new ConditionExpression("objectid", ConditionOperator.In, Col.Entities.Select(x => x.Attributes["new_documentmanagementsystemid"]).ToArray())); } } // filter1.Conditions.Add(new ConditionExpression("createdon", ConditionOperator.OnOrAfter, Convert.ToDateTime(StartDate).ToString("yyyy-MM-dd"))); // filter1.Conditions.Add(new ConditionExpression("createdon", ConditionOperator.OnOrBefore, Convert.ToDateTime(EndDate).ToString("yyyy-MM-dd"))); if (PortalUser != null) { filter1.Conditions.Add(new ConditionExpression("subject", ConditionOperator.Like, "%" + PortalUser + "%")); } FilterExpression filter2 = new FilterExpression(LogicalOperator.Or); if (Search != null) { var splitted = Search.Split(' '); for (int i = 0; i < splitted.Count(); i++) { filter2.Conditions.Add(new ConditionExpression("notetext", ConditionOperator.Like, "%" + splitted[i].ToString() + "%")); } } filter.AddFilter(filter1); filter.AddFilter(filter2); Query.Criteria = filter; Query.AddOrder("createdon", OrderType.Descending); Cols = _service.RetrieveMultiple(Query); } } else { QueryExpression Query = new QueryExpression(EntityName); Query.ColumnSet = new ColumnSet(new[] { "subject", "notetext", "objectid", "annotationid", "createdby", "createdon", "filename", "documentbody", "mimetype" }); //Query.LinkEntities.Add(new LinkEntity(EntityName, "mhl_portalnoteshared", "annotationid", "mhl_documentnotesid", JoinOperator.Natural)); //Query.LinkEntities[0].Columns.AddColumns("mhl_approvalstatus", "mhl_approvedby"); FilterExpression filter = new FilterExpression(LogicalOperator.And); FilterExpression filter1 = new FilterExpression(LogicalOperator.And); if (Id != Guid.Empty) { filter1.Conditions.Add(new ConditionExpression("objectid", ConditionOperator.Equal, Id)); } else { QueryExpression query = new QueryExpression("new_documentmanagementsystem"); query.ColumnSet = new ColumnSet(true); EntityCollection Col = _service.RetrieveMultiple(query); if (Col != null && Col.Entities.Count > 0) { filter1.Conditions.Add(new ConditionExpression("objectid", ConditionOperator.In, Col.Entities.Select(x => x.Attributes["new_documentmanagementsystemid"]).ToArray())); } } // filter1.Conditions.Add(new ConditionExpression("createdon", ConditionOperator.OnOrAfter, Convert.ToDateTime(StartDate).ToString("yyyy-MM-dd"))); // filter1.Conditions.Add(new ConditionExpression("createdon", ConditionOperator.OnOrBefore, Convert.ToDateTime(EndDate).ToString("yyyy-MM-dd"))); if (PortalUser != null) { filter1.Conditions.Add(new ConditionExpression("subject", ConditionOperator.Like, "%" + PortalUser + "%")); } FilterExpression filter2 = new FilterExpression(LogicalOperator.Or); if (Search != null) { var splitted = Search.Split(' '); for (int i = 0; i < splitted.Count(); i++) { filter2.Conditions.Add(new ConditionExpression("notetext", ConditionOperator.Like, "%" + splitted[i].ToString() + "%")); } } filter.AddFilter(filter1); filter.AddFilter(filter2); Query.Criteria = filter; Query.AddOrder("createdon", OrderType.Descending); Cols = _service.RetrieveMultiple(Query); } if (Cols != null && Cols.Entities.Count > 0) { for (int i = 0; i < Cols.Entities.Count; i++) { ConfigEntity = Cols.Entities[i]; if (ConfigEntity != null) { //EntityReference objectid = new EntityReference("incident", (Guid)ConfigEntity.Attributes["objectid"]); BL.NotesData Data = new BL.NotesData(); QueryExpression QueryShared = new QueryExpression("mhl_portalnoteshared"); QueryShared.ColumnSet = new ColumnSet(true); QueryShared.Criteria.AddCondition(new ConditionExpression("mhl_documentnotesid", ConditionOperator.Equal, new Guid(ConfigEntity.Attributes["annotationid"].ToString()).ToString().Replace("{", "").Replace("}", ""))); EntityCollection ColsShared = _service.RetrieveMultiple(QueryShared); if (ColsShared.Entities.Count > 0) { Entity ConfigEntityNew = new Entity(); ConfigEntityNew = ColsShared.Entities[0]; if (ConfigEntityNew.Attributes.Contains("mhl_approvedby")) { Data.ApprovedBy = ((EntityReference)(ConfigEntityNew["mhl_approvedby"])).Id.ToString(); } if (ConfigEntityNew.Attributes.Contains("mhl_approvalstatus")) { Data.ApprovalStatus = ((OptionSetValue)(ConfigEntityNew["mhl_approvalstatus"])).Value.ToString(); } } lst.Add(Data); } } } BL.DashboardData DashData = new BL.DashboardData(); DashData.Approved = lst.Where(x => x.ApprovalStatus == "125970000").Count().ToString(); DashData.Reject = lst.Where(x => x.ApprovalStatus == "125970001").Count().ToString(); DashData.Pending = lst.Where(x => x.ApprovalStatus == "125970002").Count().ToString(); DashData.Processed = lst.Where(x => x.ApprovalStatus == "125970003").Count().ToString(); //125970000 //125970001 // 125970002 return(DashData); }