-
Notifications
You must be signed in to change notification settings - Fork 0
/
BrandManager.cs
61 lines (55 loc) · 1.55 KB
/
BrandManager.cs
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
using Business.Abstract;
using Business.Constants;
using Core.Utilities.Business;
using Core.Utilities.Results;
using Entities.Concrete;
using System;
using System.Collections.Generic;
using System.Text;
namespace Business.Concrete
{
public class BrandManager : IBrandService
{
IBrandDal _brandDal;
public BrandManager(IBrandDal brandDal)
{
_brandDal = brandDal;
}
public IDataResult<List<Brand>> GetAll()
{
return new SuccessDataResult<List<Brand>>(_brandDal.GetAll());
}
public IDataResult<Brand> GetById(int brandId)
{
return new SuccessDataResult<Brand>(_brandDal.Get(b => b.BrandId == brandId));
}
public IResult AddBrand(Brand brand)
{
_brandDal.Add(brand);
return new SuccessResult();
}
public IResult DeleteBrand(Brand brand)
{
_brandDal.Delete(brand);
return new SuccessResult();
}
public IResult UpdateBrand(Brand brand)
{
IResult result = BusinessRules.Run(BrandExists(brand.BrandId));
if (result != null)
{
return result;
}
_brandDal.Update(brand);
return new SuccessResult();
}
private IResult BrandExists(int id)
{
if (_brandDal.Exists(b => b.BrandId == id))
{
return new SuccessResult();
}
return new ErrorResult(Messages.ColorNotFound);
}
}
}