| | | 1 | | using System; |
| | | 2 | | using System.Collections.Generic; |
| | | 3 | | using CounterDrone.Core.Models; |
| | | 4 | | using CounterDrone.Core.Repository; |
| | | 5 | | |
| | | 6 | | namespace CounterDrone.Core.Services |
| | | 7 | | { |
| | | 8 | | public class GroupService : IGroupService |
| | | 9 | | { |
| | | 10 | | private readonly GroupRepository _repo; |
| | | 11 | | |
| | 5 | 12 | | public GroupService(GroupRepository repo) |
| | 5 | 13 | | { |
| | 5 | 14 | | _repo = repo; |
| | 5 | 15 | | } |
| | | 16 | | |
| | | 17 | | public Group CreateGroup(string name, GroupType type, string description) |
| | 7 | 18 | | { |
| | 7 | 19 | | if (string.IsNullOrWhiteSpace(name)) |
| | 1 | 20 | | throw new ArgumentException("编组名称不能为空"); |
| | | 21 | | |
| | 6 | 22 | | var group = new Group |
| | 6 | 23 | | { |
| | 6 | 24 | | Name = name, |
| | 6 | 25 | | GroupType = (int)type, |
| | 6 | 26 | | Description = description, |
| | 6 | 27 | | }; |
| | | 28 | | |
| | 6 | 29 | | _repo.Insert(group); |
| | 6 | 30 | | return group; |
| | 6 | 31 | | } |
| | | 32 | | |
| | | 33 | | public void DeleteGroup(string id) |
| | 1 | 34 | | { |
| | 1 | 35 | | _repo.Delete(id); |
| | 1 | 36 | | } |
| | | 37 | | |
| | | 38 | | public List<Group> GetGroups(GroupType? type) |
| | 2 | 39 | | { |
| | 2 | 40 | | if (type.HasValue) |
| | 1 | 41 | | return _repo.GetByType((int)type.Value); |
| | 1 | 42 | | return _repo.GetAll(); |
| | 2 | 43 | | } |
| | | 44 | | |
| | | 45 | | public Group GetGroup(string id) |
| | 2 | 46 | | { |
| | 2 | 47 | | return _repo.GetById(id); |
| | 2 | 48 | | } |
| | | 49 | | } |
| | | 50 | | } |