aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ResultsController.cs
blob: 577c75ad22ccc515a263e6107319472a6efa28a6 (plain)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Tango.TCC.BL.Entities;
using Tango.TCC.Service.DB;
using Tango.TCC.Service.DTO;
using Tango.TCC.Service.Security;
using Tango.Web.Controllers;
using System.Data.Entity;
using Tango.TCC.BL.Web;
using Tango.TCC.Service.Storage;
using System.Web.Http.Results;
using Tango.TCC.Service.Filters;
using Microsoft.AspNet.SignalR;
using Tango.TCC.Service.Hubs;

namespace Tango.TCC.Service.Controllers
{
    public class ResultsController : TangoController<TokenObject>
    {
        [JwtTokenFilter]
        [HttpGet]
        public List<ResultDTO> GetResults([FromUri] ResultsByDateRequest request)//int count)
        {
            List<ResultDTO> results = new List<ResultDTO>();

            using (var db = TccDbContext.CreateTCC())
            {
                DateTime start, end;
                if (!DateTime.TryParse(request.From, out start) || !DateTime.TryParse(request.To, out end))
                {
                    return results;
                }


                var dbResults = (from RESULTS in db.Results
                                 where DbFunctions.TruncateTime(RESULTS.Date) >= start.Date && DbFunctions.TruncateTime(RESULTS.Date) <= end.Date
                                 join CARDS in db.Cards on RESULTS.CardGuid equals CARDS.Guid
                                 join DEVICES in db.Devices on RESULTS.DeviceGuid equals DEVICES.Guid
                                 where (request.Email == null || DEVICES.Email == request.Email) && (request.DeviceModel == null || DEVICES.DeviceModel == request.DeviceModel)
                                 select new
                                 {
                                     Result = RESULTS,
                                     DeviceModel = DEVICES.DeviceModel,
                                     Email = DEVICES.Email,
                                     CardCode = CARDS.Code,
                                     DeviceID = DEVICES.DeviceID
                                 }).ToList(); 


                foreach (var item in dbResults)
                {
                    ResultDTO dto = ResultDTO.createResultDTO(item.Result, item.CardCode, item.DeviceModel, item.Email, item.DeviceID);
                    results.Add(dto);
                }
            }

            return results;
        }
        [JwtTokenFilter]
        [HttpGet]
        public List<ResultDTO> GetLastResults([FromUri] ResultsByCountRequest request)//int count)
        {
            List<ResultDTO> results = new List<ResultDTO>();

            using (var db = TccDbContext.CreateTCC())
            {
                var dbResults = db.Results.ToList().TakeLast(request.Count);

                foreach (var item in dbResults)
                {
                    ResultDTO dto = ResultDTO.createsampleResultDTO(item);
                    results.Add(dto);
                }
            }

            return results;
        }
        [HttpGet]
        public RedirectResult GetResultSampleImage(String blobName)
        {
            return Redirect(TCCStorageManager.CreateSampleImageURL(blobName));
        }

        [HttpGet]
        public RedirectResult GetResultSourceImage(String blobName)
        {
            return Redirect(TCCStorageManager.CreateSourceImageURL(blobName));
        }
        [JwtTokenFilter]
        [HttpPost]
        public VerificationResponse VerifyDeviceEmail(VerificationRequest request)//int count)
        {
            VerificationResponse response = new VerificationResponse();
            response.Verified = false;

            using (var db = TccDbContext.CreateTCC())
            {
                var device = db.Devices.FirstOrDefault(x => x.Email == request.Email);
                if (device != null)
                {
                    response.Verified = true;
                }
            }
            return response;
        }
        [HttpPost]
        public void Test()
        {
            var myHub = GlobalHost.ConnectionManager.GetHubContext<ResultsHub>() as ResultsHub;
            ResultDTO dto = new ResultDTO();
            dto.Guid = "123";
            dto.Date = DateTime.Now;
            dto.RawColor = -100000;
            dto.ProcessedColor = -100000;
            dto.SampleImageURL = "";
            dto.SourceImageURL = "";
            dto.ProcessTime = 55;
            dto.CardGuid = "";
            dto.CardCode = "";
            dto.DeviceModel = "aaa";
            dto.Email = "Victoria.Plitt@twine-s.com";
            dto.DeviceGuid = "";
            ResultsHub.PushResult(dto);
        }
    }
}