Ejemplo n.º 1
0
        public ActionResult SetLookUser(long id, bool isLook)
        {
            var db = followEventService.FindEntity(x => x.Id == id);

            if (db.IsLook && db.LockById != CurrenUser.DeptId && CurrenUser.IsDepManager() && !CurrenUser.IsAdmin())
            {
                var value = new
                {
                    Views       = "This locked by director. Please contact him for unlock",
                    Title       = "Error!",
                    ColumnClass = "col-md-6 col-md-offset-3"
                };
                return(JsonResult(value, true));
            }
            followEventService.Look(id, isLook, CurrenUser);
            db = followEventService.FindEntity(x => x.Id == id);
            var view = this.RenderPartialView("_UserFollowItem", db);

            return(Json(view, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public ActionResult CalendarView()
        {
            ViewData["UserSalesList"] = usersServices.GetAllSales(CurrenUser, false);
            var current = DateTime.Now;
            var filter  = new EventFilter()
            {
                Year    = current.Year,
                Month   = current.Month,
                Sales   = 0,
                OfEvent = null
            };

            ViewBag.filter = filter;
            var qrEvents =
                eventService.GetQuery(x => x.DateBegin.Month == current.Month &&
                                      x.DateBegin.Year == current.Year);

            if (!CurrenUser.IsDirecter())
            {
                if (CurrenUser.IsDepManager())
                {
                    qrEvents = qrEvents.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
                {
                    qrEvents = qrEvents.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)));
                }
            }
            var list = qrEvents.ToList();

            Session[CALENDAR_SEARCH_MODEL] = filter;
            return(View(list));
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        public ActionResult CalendarView(string type, EventFilter filter)
        {
            ViewData["UserSalesList"] = usersServices.GetAllSales(CurrenUser, false);
            var currentFilter = (EventFilter)Session[CALENDAR_SEARCH_MODEL];

            if (filter.Month == 0)
            {
                filter = currentFilter;
            }
            var dateOfMonth = new DateTime(filter.Year, filter.Month, 1);

            if (!filter.Sales.HasValue)
            {
                filter.Sales = 0;
            }

            switch (type)
            {
            case "prev":
                dateOfMonth = dateOfMonth.AddMonths(-1);
                break;

            case "current":
                dateOfMonth = DateTime.Now;
                break;

            case "next":
                dateOfMonth = dateOfMonth.AddMonths(1);
                break;
            }
            filter.Month = dateOfMonth.Month;
            filter.Year  = dateOfMonth.Year;
            var qrEvents =
                eventService.GetQuery(x => (x.DateBegin.Month == filter.Month && x.DateBegin.Year == filter.Year) &&
                                      (filter.Sales == 0 || (filter.Sales == x.CreatedById ||
                                                             (x.CRMCustomer.CreatedById == filter.Sales) ||
                                                             (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)
            {
                qrEvents = filter.OfEvent == TypeOfEvent.Events ? qrEvents.Where(x => x.IsEventAction == true) : qrEvents.Where(x => x.IsEventAction == false);
            }
            if (!CurrenUser.IsDirecter() && filter.Sales == 0)
            {
                if (CurrenUser.IsDepManager())
                {
                    qrEvents = qrEvents.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
                {
                    qrEvents = qrEvents.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)));
                }
            }

            var list = qrEvents.ToList();

            Session[CALENDAR_SEARCH_MODEL] = filter;
            ViewBag.filter = filter;
            return(PartialView("_CalendarModelView", list));
        }