aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ResultsController.cs
blob: 428eb0b36a9dc70f454eadc216c5ee9d08a25cdd (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
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;

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 into prodGroup
                                 from DEVICES2 in prodGroup
                                 where (request.Email == null || DEVICES2.Email == request.Email) && (request.DeviceModel == null || DEVICES2.DeviceModel == request.DeviceModel)
                                 select new
                                 {
                                     Result = RESULTS,
                                     DeviceModel = DEVICES2.DeviceModel,
                                     Email = DEVICES2.Email,
                                     CardCode = CARDS.Code,
                                     DeviceID = DEVICES2.DeviceID
                                 }).ToList(); ;//.Where(x => (request.Email == null || x.Email == request.Email) && (request.DeviceModel == null || x.DeviceModel.Contains(request.DeviceModel))).ToList();


                foreach (var item in dbResults)
                {
                    ResultDTO dto = new ResultDTO();
                    dto.ID = item.Result.ID;
                    dto.Date = item.Result.Date;
                    dto.RawColor = item.Result.RawColor;
                    dto.ProcessedColor = item.Result.ProcessedColor;
                    dto.SampleImageURL = "/api/Results/GetResultSampleImage?blobName=" + item.Result.SampleImageBlobName;
                    dto.SourceImageURL = "/api/Results/GetResultSourceImage?blobName=" + item.Result.SourceImageBlobName;
                    dto.ProcessTime = item.Result.ProcessTime;
                    dto.CardGuid = item.Result.CardGuid;
                    dto.CardCode = item.CardCode;
                    dto.DeviceModel = item.DeviceModel;
                    dto.Email = item.Email;
                    dto.DeviceGuid = item.DeviceID;
                    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));
        }
    }
}