forked from yuezhongxin/MessageManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessage.cs
More file actions
90 lines (86 loc) · 2.93 KB
/
Copy pathMessage.cs
File metadata and controls
90 lines (86 loc) · 2.93 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* author:xishuai
* address:https://www.github.com/yuezhongxin/MessageManager
**/
using MessageManager.Domain.ValueObject;
using System;
namespace MessageManager.Domain.Entity
{
public class Message : IAggregateRoot
{
public Message(string title, string content, Contact sender, Contact recipient)
{
if (string.IsNullOrEmpty(title))
{
throw new ArgumentException("title can't be null");
}
if (title.Length > 20)
{
throw new ArgumentException("标题长度不能超过20");
}
if (string.IsNullOrEmpty(content))
{
throw new ArgumentException("content can't be null");
}
if (content.Length > 400)
{
throw new ArgumentException("内容长度不能超过400");
}
if (sender == null)
{
throw new ArgumentException("sender can't be null");
}
if (recipient == null)
{
throw new ArgumentException("recipient can't be null");
}
this.ID = Guid.NewGuid().ToString();
this.Title = title;
this.Content = content;
this.SendTime = DateTime.Now;
this.State = MessageState.Unread;
this.DisplayType = MessageDisplayType.OutboxAndInbox;
this.Sender = sender;
this.Recipient = recipient;
}
public string ID { get; private set; }
public string Title { get; private set; }
public string Content { get; private set; }
public DateTime SendTime { get; private set; }
public MessageState State { get; private set; }
public MessageDisplayType DisplayType { get; private set; }
public virtual Contact Sender { get; private set; }
public virtual Contact Recipient { get; private set; }
public void SetState(Contact reader)
{
if (this.Recipient.Name.Equals(reader.Name) && this.State == MessageState.Unread)
{
this.State = MessageState.Read;
}
}
public bool SetDisplayType(Contact reader)
{
// to do...
switch (this.DisplayType)
{
case MessageDisplayType.OutboxAndInbox:
if (this.Sender.Name.Equals(reader.Name))
{
this.DisplayType = MessageDisplayType.Inbox;
}
else
{
this.DisplayType = MessageDisplayType.Outbox;
}
return true;
case MessageDisplayType.Outbox:
break;
case MessageDisplayType.Inbox:
break;
default:
break;
}
return false;
}
}
}