-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserServices.cs
87 lines (78 loc) · 1.91 KB
/
UserServices.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using DataTransferObjects;
using IBL;
using IDAL;
namespace BL
{
public class UserServices : IUserBL
{
private readonly IUserDAL userDal;
public UserServices(IUserDAL _userDal)
{
userDal = _userDal;
}
public bool AddNew(UserDTO user)
{
try
{
var success = userDal.AddNew(user);
if (!success)
{
Console.WriteLine("Failed to add user in BL.");
}
return success;
}
catch (Exception ex)
{
Console.WriteLine($"Error in AddNew method: {ex.Message}");
return false;
}
}
public bool Delete(int id)
{
try
{
UserDTO userDto = userDal.GetAll().Find(user => user.UserId == id) ?? new UserDTO();
return userDal.Delete(userDto);
}
catch (Exception)
{
return false;
}
}
public UserDTO Get(int id)
{
try
{
UserDTO userDto = userDal.GetAll().Find(user => user.UserId == id) ?? new UserDTO();
return userDto;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
}
public List<UserDTO> GetAll()
{
try
{
return userDal.GetAll();
}
catch (Exception)
{
return new List<UserDTO>();
}
}
public bool Update(UserDTO user)
{
try
{
return userDal.Update(user);
}
catch (Exception)
{
return false;
}
}
}
}