SearchController.cs 2.88 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System.Linq;
using Coscine.Api.Project.Models;
using Coscine.ApiCommons;
using Coscine.ApiCommons.Utils;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using VDS.RDF.Query.Expressions.Functions.Sparql.String;

namespace Coscine.Api.Project.Controllers
{
    public class SearchController : Controller
    {
        private readonly Authenticator _authenticator;
        private DatabaseConnection _databaseConnection;
        private readonly ProjectModel _projectModel;


        public SearchController()
        {
            _authenticator = new Authenticator(this, Program.Configuration);
            _projectModel = new ProjectModel();
            _databaseConnection = new DatabaseConnection(Program.Configuration);

        }

        [Route("[controller]")]
        public IActionResult Index()
        {
            return Ok(_authenticator.ValidateAndExecute((user) =>
            {
                string searchQuery = "";
                return _databaseConnection.ConnectToDatabase((db) =>
            {
                return
                    (from p in db.Projects
                        join v in db.Visibilities on p.VisibilityId equals v.Id
                        join pd in db.ProjectDisciplines on p.Id equals pd.ProjectId
                        join d in db.Disciplines on pd.DisciplineId equals d.Id
                        join pi in db.ProjectInstitutes on p.Id equals pi.ProjectId
                        join i in db.Institutes on pi.InstituteId equals i.Id

                     where p.ProjectName.Contains(searchQuery) ||
                           p.Description.Contains(searchQuery) ||
                           p.StartDate.ToString().Contains(searchQuery) ||
                           p.EndDate.ToString().Contains(searchQuery) ||
                           p.Keywords.Contains(searchQuery) ||
                           p.DisplayName.Contains(searchQuery) ||
                           p.PrincipleInvestigators.Contains(searchQuery) ||
                           p.GrantId.Contains(searchQuery) ||
                           v.DisplayName.Contains(searchQuery) ||
                           d.Url.Contains(searchQuery) ||
                           d.DisplayNameDe.Contains(searchQuery) ||
                           d.DisplayNameEn.Contains(searchQuery) ||
                           i.DisplayName.Contains(searchQuery) ||
                           i.IKZ.Contains(searchQuery) 

                     select new {p.Id, p.DisplayName});
            });
            }));

            /*
            return DatabaseConnection.ConnectToDatabase((db) => (from relation in db.ProjectRoles
                where relation.Project == project
                      && relation.User == user
                      && (relation.Role.DisplayName == "Owner"
                          || relation.Role.DisplayName == "Member")
                select relation).Any());*/
        }
    }
}