aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio_v2/Tango.BLL/Services/MachinesService.cs
blob: 41e81ab2d49a3955ded106fc4a3db508950eb0b5 (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
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Tango.BLL.Mappers;
using Tango.BLL.Objects;
using Tango.DAL;
using Tango.DAL.Entities;
using System.Linq;

namespace Tango.BLL.Services
{
    public class MachinesService : ServiceBase<Machine>
    {
        private IRepository<MachineEntity> _repository;
        private MachineToMachineEntityMapper _mapper;

        public MachinesService(IRepository<MachineEntity> repository)
        {
            _repository = repository;
            _mapper = new MachineToMachineEntityMapper();
        }

        public async Task<Machine> AddMachine(Machine machine)
        {
            MachineEntity entity = _mapper.Create(machine);
            entity = await _repository.Insert(entity);
            _mapper.Map(entity, machine);
            return machine;
        }

        public async Task<List<Machine>> GetOrganizationMachines(string organizationID)
        {
            return (await _repository.GetAsync(x => x.OrganizationID == organizationID)).
                ToList()
                .Select(x => _mapper.Create(x)).ToList();
        }
    }
}