Ejemplo n.º 1
0
        public ActionResult Search(string searchTitle)
        {
            var project = db.Projects
                          .Include(p => p.Category)
                          .Include(p => p.User)
                          .Include(p => p.BackerProjects)
                          .Include(p => p.UserProjectComments)
                          .Where(p => p.Title.Contains(searchTitle))
                          .Select(y => new BasicProjectInfoViewModel()
            {
                Id                 = y.Id,
                CategoryId         = y.CategoryId,
                CategoryName       = y.Category.Name,
                Title              = y.Title,
                CreatorFullName    = y.User.AspNetUser.FirstName + " " + y.User.AspNetUser.LastName,
                Description        = y.Description,
                CurrentFund        = y.CurrentFundAmount,
                Ratio              = (int)(((double)y.CurrentFundAmount / y.TargetAmount) * 100),
                CurrentBackerCount = y.BackerProjects.Where(x => x.ProjectId == y.Id).Count(),
                DueDate            = y.DueDate,
                NoComments         = y.UserProjectComments.Where(x => x.ProjectId == y.Id).Count(),
                ImageUrl           = y.PhotoUrl
            });

            var viewModel = new ProjectSearchViewModel()
            {
                Query           = searchTitle,
                DisplayProjects = project.ToList()
            };

            return(View("Search", viewModel));
        }
Ejemplo n.º 2
0
        public async Task <Tuple <int, List <ProjectDTO> > > LoadAsyncCountAdmin(

            int skip = -1,
            int take = -1,
            ProjectSearchViewModel model = null)
        {
            var query = Entities

                        .ProjectTo <ProjectDTO>();



            switch (model.RoutinStatus)
            {
            case RoutineSSOT.New:
                query = query.Where(x => x.Status == ProjectStatusSSOT.Admin);
                break;

            case RoutineSSOT.Posted:
                query = query.Where(x => x.Status > ProjectStatusSSOT.Admin
                                    &&
                                    x.Status != ProjectStatusSSOT.Success &&
                                    x.Status != ProjectStatusSSOT.Deny);
                break;

            case RoutineSSOT.Ended:
                query = query.Where(x => x.Status == ProjectStatusSSOT.Success || x.Status == ProjectStatusSSOT.Deny);
                break;

            default:
                query = query.Where(x => x.Status == ProjectStatusSSOT.Customer);
                break;
            }


            if (!string.IsNullOrEmpty(model.Title))
            {
                query = query.Where(x => x.Title.Contains(model.Title));
            }



            int Count = query.Count();

            query = query.OrderByDescending(x => x.Id);


            if (skip != -1)
            {
                query = query.Skip((skip - 1) * take);
            }

            if (take != -1)
            {
                query = query.Take(take);
            }

            return(new Tuple <int, List <ProjectDTO> >(Count, await query.ToListAsync()));
        }
        public IActionResult Search(SearchProjectOptions options)
        {
            var viewModel = new ProjectSearchViewModel()
            {
                ProjectList = projectService
                              .SearchProject(options)
                              .ToList()
            };

            return(View(viewModel));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Index(ProjectSearchViewModel searchModel)
        {
            ViewBag.Organizations = await _organizationRepository.GetAllMapAsync <OrganizationIdTitleDTO>();

            var model = await _projectRepository.LoadAsyncCountAdmin(
                this.CurrentPage,
                this.PageSize,
                searchModel);

            this.TotalNumber    = model.Item1;
            ViewBag.SearchModel = searchModel;

            return(View(model.Item2));
        }
        public async Task <IActionResult> Index(ProjectSearchViewModel searchModel)
        {
            ViewBag.Organizations = await _userOrganizationRepository.GetOrganizationFullByUserId(this.UserId);

            var model = await _projectRepository.LoadAsyncCountAdminCustomer(
                UserId,
                this.CurrentPage,
                this.PageSize,
                searchModel);

            this.TotalNumber    = model.Item1;
            ViewBag.SearchModel = searchModel;

            return(View(model.Item2));
        }
Ejemplo n.º 6
0
        public async Task <ActionResult> Search(string projectName)
        {
            var response = await _dataClient.SearchProjects(projectName);

            var allCategories = await _dataClient.GetProjectCategories();

            var model = new ProjectSearchViewModel
            {
                SearchResultCount = response.Data != null?response.Data.Count() : 0,
                                        SearchResults = response.Data != null ? response.Data : new List <ProjectViewModel>(),
                                        AllCategories = allCategories.Data != null ? allCategories.Data : new List <ProjectCategoryViewModel>(),
            };

            return(View(model));
        }
        public async Task <IActionResult> Search(string search)
        {
            // Creating an instance of the view model for the search feature
            ProjectSearchViewModel viewmodel = new ProjectSearchViewModel();
            //Retrieving the user that is currently logged in
            var user = await GetCurrentUserAsync();

            // Setting the string from the search bar as the Search property in the view model for the search view
            viewmodel.Search = search;
            // Retrieving all the projects from the database that have the current user attached to the project and that have a title containing the search parameter. These projects will be displayed in a table for the search view
            viewmodel.Projects = await _context.Project
                                 .Where(p => p.Title.Contains(search) && p.User == user)
                                 .ToListAsync();

            return(View(viewmodel));
        }
Ejemplo n.º 8
0
        public ActionResult Index(PagerParametersWithSortFields pagerParameters, string searchPhrase, string contentTypes, int?projectId)
        {
            if (!this.contentOwnershipService.IsCurrentUserCustomer() &&
                !this.contentOwnershipService.IsCurrentUserOperator())
            {
                return(new HttpUnauthorizedResult());
            }

            var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);

            var matchedContentTypes = string.IsNullOrEmpty(contentTypes) ?
                                      contentTypes.Split(',').Where(c => this.searchFieldsBasedOnContentType.Any(d => d.Key == c)) :
                                      this.searchFieldsBasedOnContentType.Keys;

            if (matchedContentTypes.Count() == 0)
            {
                matchedContentTypes = this.searchFieldsBasedOnContentType.Keys;
            }

            var fields = this.searchFieldsBasedOnContentType
                         .Where(c => matchedContentTypes.Any(d => d == c.Key))
                         .SelectMany(d => d.Value)
                         .Distinct()
                         .ToArray();

            IPageOfItems <IContent> searchHits = null;

            try
            {
                searchHits = _projectSearchService.Query(pagerParameters, searchPhrase, projectId, matchedContentTypes.ToArray(), fields);
            }
            catch (Exception exception)
            {
                Logger.Error(T("Invalid search query: {0}", exception.Message).Text);
            }

            var list = Shape.List();

            foreach (var contentItem in searchHits)
            {
                var     contentType = contentDefinitionManager.GetTypeDefinition(contentItem.ContentItem.ContentType);
                dynamic model       = new ExpandoObject();
                model.Shape = _contentManager.BuildDisplay(contentItem, "Summary");
                model.ContentTypeDisplayName = contentType.DisplayName;
                list.Add(model);
            }



            var pagerShape      = Shape.Pager(pager).TotalItemCount(searchHits.TotalItemCount);
            var searchViewModel = new ProjectSearchViewModel
            {
                Query          = searchPhrase,
                TotalItemCount = searchHits.TotalItemCount,
                StartPosition  = (pager.Page - 1) * pager.PageSize + 1,
                EndPosition    = pager.Page * pager.PageSize > searchHits.TotalItemCount ? searchHits.TotalItemCount : pager.Page * pager.PageSize,
                ContentItems   = list,
                ProjectId      = projectId,
                ContentTypes   = contentTypes,
                Pager          = pagerShape
            };

            if (projectId.HasValue)
            {
                var project = this.projectService.GetProject(projectId.Value);
                searchViewModel.ProjectName = project != null ? project.Title : string.Empty;
            }

            return(View(searchViewModel));
        }
Ejemplo n.º 9
0
        public ActionResult Tree(ProjectSearchViewModel vm)
        {
            // Special Case for getting parent Id = null
            ViewBag.ParentId = new SelectList(_projectRepository.GetAllBy(p => p.ParentId == null).OrderBy(p => p.Title), "Id", "Title");

            Func <IQueryable <Project>, IQueryable <Project> > projectFilter = q =>
            {
                q = q.Include(p => p.Client).Include(p => p.ParentProject);

                if (vm.IsPublic.HasValue)
                {
                    q = q.Where(r => r.IsPublic == vm.IsPublic.Value);
                }

                if (vm.ClientId.HasValue)
                {
                    q = q.Where(r => r.ClientId == vm.ClientId.Value);
                }

                if (vm.ParentId.HasValue)
                {
                    q = q.Where(r => r.ParentId == vm.ParentId.Value);
                }

                if (!string.IsNullOrEmpty(vm.Title))
                {
                    q = q.Where(r => r.Title.Contains(vm.Title));
                }

                if (vm.Status.HasValue)
                {
                    q = q.Where(r => r.Status == vm.Status.Value);
                }

                if (vm.Billing.HasValue)
                {
                    q = q.Where(r => r.Billing == vm.Billing.Value);
                }

                if (!WebUser.IsAdmin)
                {
                    // Restrict to Projects to which i am a Member
                    var employee   = _employeeRepository.GetBy(u => u.UserId == WebUser.Id, "User,User.Person,ReportingPerson.User.Person,Manager.User.Person,Location,Department,Designation,Shift");
                    var myProjects = _projectMemberRepository.GetAllBy(m => m.EmployeeId == employee.Id).Select(m => m.ProjectId).Distinct().ToList();
                    q = q.Where(p => myProjects.Contains(p.Id));
                }

                q = q.OrderByDescending(c => c.UpdatedOn);

                return(q);
            };

            vm.Projects = _projectRepository.Search(projectFilter).ToList();

            vm.TreeNodes = vm.Projects.Select(p => new ProjectTreeNode
            {
                id     = p.Id.ToString(CultureInfo.InvariantCulture),
                text   = p.Title,
                parent = p.ParentId?.ToString(CultureInfo.InvariantCulture) ?? "#"
            }).ToList();

            return(View(vm));
        }
Ejemplo n.º 10
0
        public ActionResult Index(ProjectSearchViewModel vm)
        {
            ViewBag.IsAdmin = WebUser.IsAdmin;

            ViewBag.ParentId = new SelectList(_projectRepository.GetAllBy(p => p.ParentId == null).OrderBy(p => p.Title), "Id", "Title");

            Func <IQueryable <Project>, IQueryable <Project> > projectFilter = q =>
            {
                q = q.Include(p => p.Client).Include(p => p.ParentProject);

                if (vm.IsPublic.HasValue)
                {
                    q = q.Where(r => r.IsPublic == vm.IsPublic.Value);
                }

                if (vm.ClientId.HasValue)
                {
                    q = q.Where(r => r.ClientId == vm.ClientId.Value);
                }

                if (vm.ParentId.HasValue)
                {
                    q = q.Where(r => r.ParentId == vm.ParentId.Value);
                }

                if (!string.IsNullOrEmpty(vm.Title))
                {
                    q = q.Where(r => r.Title.Contains(vm.Title));
                }

                if (vm.Status.HasValue)
                {
                    q = q.Where(r => r.Status == vm.Status.Value);
                }

                if (vm.Billing.HasValue)
                {
                    q = q.Where(r => r.Billing == vm.Billing.Value);
                }

                if (!vm.ShowClosedProjects)
                {
                    q = q.Where(r => r.Status != ProjectStatus.Closed);
                }

                if (!WebUser.IsAdmin)
                {
                    // Restrict to Projects to which i am a Member or project is public
                    var employee   = _employeeRepository.GetBy(u => u.UserId == WebUser.Id, "User,User.Person,ReportingPerson.User.Person,Manager.User.Person,Location,Department,Designation,Shift");
                    var myProjects = _projectMemberRepository.GetAllBy(m => m.EmployeeId == employee.Id).Select(m => m.ProjectId).Distinct().ToList();
                    q = q.Where(p => myProjects.Contains(p.Id));
                }

                q = q.OrderByDescending(d => d.UpdatedOn);

                return(q);
            };

            vm.Projects = _projectRepository.Search(projectFilter).ToList();
            return(View(vm));
        }
Ejemplo n.º 11
0
        public async Task <Tuple <int, List <ProjectDTO> > > LoadAsyncCountAdminCustomer(
            int userId,
            int skip = -1,
            int take = -1,
            ProjectSearchViewModel model = null)
        {
            var OrganizationIds = await _userOrganizationRepository.GetOrganizationByUserId(userId);


            var query = Entities

                        .ProjectTo <ProjectDTO>();

            switch (model.RoutinStatus)
            {
            case RoutineSSOT.New:
                query = query.Where(x => x.Status == ProjectStatusSSOT.AdminCustomer ||
                                    x.Status == ProjectStatusSSOT.AdminCustomerShoudPay);
                break;

            case RoutineSSOT.Posted:
                query = query.Where(x => x.Status > ProjectStatusSSOT.AdminCustomer &&
                                    x.Status != ProjectStatusSSOT.AdminCustomerShoudPay &&
                                    x.Status != ProjectStatusSSOT.Customer &&
                                    x.Status != ProjectStatusSSOT.Success &&
                                    x.Status != ProjectStatusSSOT.Deny);
                break;

            case RoutineSSOT.Ended:
                query = query.Where(x => x.Status == ProjectStatusSSOT.Success || x.Status == ProjectStatusSSOT.Deny);
                break;

            default:
                query = query.Where(x => x.Status == ProjectStatusSSOT.AdminCustomer);
                break;
            }


            if (!string.IsNullOrEmpty(model.Title))
            {
                query = query.Where(x => x.Title.Contains(model.Title));
            }


            if (OrganizationIds != null)
            {
                query = query.Where(x => OrganizationIds.Contains(x.OrganizationId));
            }
            // درصورتی که به هیچ سازمانی متصل نباشد نباید هیچ آیتمی نمایش داده شود
            else
            {
                query = query.Where(x => x.OrganizationId == -1);
            }


            // در صورتی که کاربر برای حدول مورد نظر جستجو سازمان زده باشد
            if (model.OrganizationId != null)
            {
                query = query.Where(x => x.OrganizationId == model.OrganizationId);
            }


            int Count = query.Count();

            query = query.OrderByDescending(x => x.Id);


            if (skip != -1)
            {
                query = query.Skip((skip - 1) * take);
            }

            if (take != -1)
            {
                query = query.Take(take);
            }

            return(new Tuple <int, List <ProjectDTO> >(Count, await query.ToListAsync()));
        }
Ejemplo n.º 12
0
 public ActionResult Index(ProjectSearchViewModel mdl)
 {
     return View(mdl);
 }