-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorManager.cs
61 lines (55 loc) · 1.56 KB
/
ColorManager.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 ColorManager : IColorService
{
IColorDal _colorDal;
public ColorManager(IColorDal colorDal)
{
_colorDal = colorDal;
}
public IDataResult<List<Color>> GetAll()
{
return new SuccessDataResult<List<Color>>(_colorDal.GetAll());
}
public IDataResult<Color> GetById(int colorId)
{
return new SuccessDataResult<Color>(_colorDal.Get(c => c.ColorId == colorId));
}
public IResult AddColor(Color color)
{
_colorDal.Add(color);
return new SuccessResult();
}
public IResult DeleteColor(Color color)
{
_colorDal.Delete(color);
return new SuccessResult();
}
public IResult UpdateColor(Color color)
{
IResult result = BusinessRules.Run(ColorExists(color.ColorId));
if (result != null)
{
return result;
}
_colorDal.Update(color);
return new SuccessResult();
}
private IResult ColorExists(int id)
{
if (_colorDal.Exists(c => c.ColorId == id))
{
return new SuccessResult();
}
return new ErrorResult(Messages.ColorNotFound);
}
}
}