public ActionResult Index(Grid <CRMEventModel> grid, ListEventFilter filter) { _grid = grid; _grid.ProcessAction(); Session[CRMVISITED_SEARCH_MODEL] = grid; UpdateGrid(filter); ViewData["UserSalesList"] = usersServices.GetAllSales(CurrenUser, false); ViewBag.SearchingMode = filter; return(PartialView("_List", _grid)); }
private void UpdateGrid(ListEventFilter filter = null) { filter = filter ?? new ListEventFilter(); filter.Sales = filter.Sales ?? 0; bool isEventAction = filter.OfEvent == TypeOfEvent.Events; ViewBag.IsEventAction = isEventAction; var page = _grid.Pager; var sort = new SSM.Services.SortField(string.IsNullOrEmpty(page.Sidx) ? "DateEvent" : page.Sidx, page.Sord == "asc"); var totalRow = 0; var qr = eventService.GetQuery(x => (filter.Sales == 0 || filter.Sales == x.CreatedById || (x.CRMCustomer.CRMFollowCusUsers != null && x.CRMCustomer.CRMFollowCusUsers.Any(f => f.UserId == filter.Sales)) || (x.CRMCustomer.CreatedById == CurrenUser.Id) || (x.CRMFollowEventUsers != null && x.CRMFollowEventUsers.Any(ef => ef.UserId == filter.Sales)) ) && (filter.Status == CRMEventStatus.All || x.Status == (byte)filter.Status) && (string.IsNullOrEmpty(filter.CustomerName) || x.CRMCustomer.CompanyShortName.Contains(filter.CustomerName) || x.CRMCustomer.CompanyName.Contains(filter.CustomerName))); if (filter.OfEvent.HasValue) { qr = filter.OfEvent == TypeOfEvent.Events ? qr.Where(x => x.IsEventAction == true) : qr.Where(x => x.IsEventAction == false); } if (filter.BeginDate.HasValue) { qr = qr.Where(x => x.DateEvent >= filter.BeginDate); } if (filter.EndDate.HasValue) { qr = qr.Where(x => x.DateEvent.Date <= filter.EndDate); } if (!CurrenUser.IsDirecter() && filter.Sales == 0) { if (CurrenUser.IsDepManager()) { qr = qr.Where(x => x.User.DeptId == CurrenUser.DeptId || (x.CRMCustomer.CRMFollowCusUsers != null && x.CRMCustomer.CRMFollowCusUsers.Any(f => f.UserId == CurrenUser.Id)) || (x.CRMCustomer.CreatedById == CurrenUser.Id) || (x.CRMFollowEventUsers != null && x.CRMFollowEventUsers.Any(ef => ef.UserId == CurrenUser.Id))); } else { qr = qr.Where(x => x.CreatedById == CurrenUser.Id || (x.CRMCustomer.CRMFollowCusUsers != null && x.CRMCustomer.CRMFollowCusUsers.Any(f => f.UserId == CurrenUser.Id)) || (x.CRMCustomer.CreatedById == CurrenUser.Id) || (x.CRMFollowEventUsers != null && x.CRMFollowEventUsers.Any(ef => ef.UserId == CurrenUser.Id))); } } qr = qr.OrderByDescending(x => x.DateEvent).ThenBy(sort); totalRow = qr.Count(); var list = eventService.GetListPager(qr, page.CurrentPage, page.PageSize); var listView = list.Select(x => eventService.ToModel(x)).ToList(); _grid.Pager.Init(totalRow); if (totalRow == 0) { _grid.Data = new List <CRMEventModel>(); ViewBag.TotalDisplay = string.Empty; return; } var typeOfEvent = filter.OfEvent == TypeOfEvent.Visited ? "viếng thăm" : "sự kiện"; var finished = list.Count(x => x.Status == (byte)CRMEventStatus.Finished); var follow = list.Count(x => x.Status == (byte)CRMEventStatus.Follow); string display = string.Format(Resources.Resource.CRM_EVENT_LIST_TOTAL, totalRow, typeOfEvent, finished, follow); ViewBag.TotalDisplay = display; _grid.Data = listView; }