source: FarmatikoServices/Services/MedicineService.cs@ 5d02859

Last change on this file since 5d02859 was c406ae5, checked in by DimitarSlezenkovski <dslezenkovski@…>, 4 years ago

Update Models, Repos, Services and Controllers

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[e42f61a]1using FarmatikoData.FarmatikoRepoInterfaces;
2using FarmatikoData.Models;
3using FarmatikoServices.FarmatikoServiceInterfaces;
[a55ef91]4using System;
[e42f61a]5using System.Collections.Generic;
[a55ef91]6using System.Linq;
[c406ae5]7using System.Threading.Tasks;
[e42f61a]8
9namespace FarmatikoServices.Services
10{
11 public class MedicineService : IMedicineService
12 {
13 private IMedicineRepository _medicineRepository;
14 public MedicineService(IMedicineRepository medicineRepository)
15 {
16 _medicineRepository = medicineRepository;
17 }
18
[c406ae5]19 public async void Add(Medicine medicine)
[e42f61a]20 {
[c406ae5]21 if (medicine != null)
22 await Task.Run(() => _medicineRepository.Add(medicine));
23 else throw new Exception("Can't Add medicine is null");
[e42f61a]24 }
25
[c406ae5]26 public async Task<IQueryable<Medicine>> GetAll()
[e42f61a]27 {
[c406ae5]28 return await Task.Run(() => _medicineRepository.GetAll());
[e42f61a]29 }
30
[c406ae5]31 public async Task<IQueryable<Medicine>> GetByManufacturer(string Manufacturer)
[e42f61a]32 {
[c406ae5]33 if (Manufacturer != null)
34 return await Task.Run(() => _medicineRepository.GetByManufacturer(Manufacturer));
35 else throw new Exception("Can't get, name of manufacturer is null");
[e42f61a]36 }
37
[c406ae5]38 public async Task<IQueryable<Medicine>> GetByName(string Name)
[e42f61a]39 {
[c406ae5]40 if (Name != null)
41 return await Task.Run(() => _medicineRepository.GetByName(Name));
42 else throw new Exception("Can't get, name is null");
[e42f61a]43 }
44
[c406ae5]45 public async void Remove(Medicine Medicine)
[e42f61a]46 {
[c406ae5]47 if (Medicine != null)
48 await Task.Run(() => _medicineRepository.Remove(Medicine));
49 else throw new Exception("Can't Add medicine is null");
[e42f61a]50 }
51 }
52}
Note: See TracBrowser for help on using the repository browser.