-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathBackofficeCourse.cs
More file actions
66 lines (56 loc) · 2.03 KB
/
BackofficeCourse.cs
File metadata and controls
66 lines (56 loc) · 2.03 KB
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
using System;
using System.Collections.Generic;
namespace CodelyTv.Backoffice.Courses.Domain
{
public class BackofficeCourse
{
public string Id { get; }
public string Name { get; }
public string Duration { get; }
public BackofficeCourse(string id, string name, string duration)
{
Id = id ?? throw new ArgumentNullException(nameof(id));
Name = name ?? throw new ArgumentNullException(nameof(name));
Duration = duration ?? throw new ArgumentNullException(nameof(duration));
}
private BackofficeCourse()
{
Id = string.Empty;
Name = string.Empty;
Duration = string.Empty;
}
public Dictionary<string, object> ToPrimitives()
{
return new Dictionary<string, object>
{
{ "id", Id },
{ "name", Name },
{ "duration", Duration }
};
}
public static BackofficeCourse FromPrimitives(Dictionary<string, object> body)
{
if (body == null)
{
throw new ArgumentNullException(nameof(body));
}
return new BackofficeCourse(
body["id"]?.ToString() ?? throw new InvalidOperationException("ID is missing"),
body["name"]?.ToString() ?? throw new InvalidOperationException("Name is missing"),
body["duration"]?.ToString() ?? throw new InvalidOperationException("Duration is missing")
);
}
public override bool Equals(object? obj)
{
if (this == obj) return true;
if (obj == null || GetType() != obj.GetType()) return false;
var item = obj as BackofficeCourse;
if (item == null) return false;
return Id.Equals(item.Id) && Name.Equals(item.Name) && Duration.Equals(item.Duration);
}
public override int GetHashCode()
{
return HashCode.Combine(Id, Name, Duration);
}
}
}