-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserService.cs
70 lines (63 loc) · 2.85 KB
/
UserService.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
using ComfortCare.Data.Interfaces;
using ComfortCare.Service.Interfaces;
using ComfortCare.Service.Models;
namespace ComfortCare.Service
{
/// <summary>
/// This service class works as a mediator between the gateway and the data layer
/// </summary>
public class UserService : IUserService
{
#region fields
private readonly IUserRepo _userRepo;
#endregion
#region Constructor
public UserService(IUserRepo userService)
{
_userRepo = userService;
}
#endregion
#region Methods
/// <summary>
/// This method gets the employee db model, with all the attributes needed to
/// map the data used in the UI
/// </summary>
/// <param name="userName">the initials of the employee</param>
/// <param name="password">the password of the employee</param>
/// <returns>A EmployeeSchemaModel with the users task for the current period</returns>
public EmployeeSchemaModel GetEmployeeSchema(string userName, string password)
{
var employee = _userRepo.GetUsersWorkSchedule(userName, password);
var assignmentsData = employee.EmployeeRoute
.SelectMany(route => route.RouteAssignment)
.Select(routeAssignment => new AssignmentSchemaModel
{
Title = routeAssignment.Assignment.AssignmentType.Title,
AssignmentTypeDescription = routeAssignment.Assignment.AssignmentType.AssignmentTypeDescription,
Description = routeAssignment.Assignment.AssignmentType.AssignmentTypeDescription,
CitizenName = routeAssignment.Assignment.Citizen.CitizenName,
StartDate = routeAssignment.ArrivalTime,
EndDate = routeAssignment.ArrivalTime.AddSeconds(Convert.ToDouble(routeAssignment.Assignment.AssignmentType.DurationInSeconds)),
Address = routeAssignment.Assignment.Citizen.Residence.CitizenResidence
}).ToList();
var employeeSchema = new EmployeeSchemaModel
{
Name = employee.EmployeeName,
Assignments = assignmentsData
};
return employeeSchema;
}
/// <summary>
/// This method is used to validate if the user trying to login is
/// exist in the database
/// </summary>
/// <param name="userName">the initials of the current user</param>
/// <param name="password">the password of the current user</param>
/// <returns>return true if the current user exist in the db, returns false if not</returns>
public bool ValidateUser(string userName, string password)
{
return _userRepo.ValidateUserExist(userName, password);
}
#endregion
}
}