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

namespace Tango.TCC.Service.Controllers
{
    public class ResultsController : TangoController<TokenObject>
    {
        [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 RESULTS.Date >= start && RESULTS.Date <= end
                         join DEVICES in db.Devices on RESULTS.DeviceGuid equals DEVICES.Guid
                         join CARDS in db.Cards on RESULTS.CardGuid equals CARDS.Guid
                         select new
                         {
                             Result = RESULTS,
                             DeviceModel = DEVICES.DeviceModel,
                             Email = DEVICES.Email,
                             CardCode = CARDS.Code,
                             DeviceID = DEVICES.DeviceID
                         }).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.Date = item.Result.Date;
                    dto.RawColor = item.Result.RawColor;
                    dto.ProcessedColor = item.Result.ProcessedColor;
                    dto.SampleImageBlobName = item.Result.SampleImageBlobName;
                    dto.SourceImageBlobName = 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;
        }


    }
}