aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/src/Models/Database/BaseWithOwner.cs
blob: 3c29c7633b2b91475442181b9e6404d92c2e5e13 (plain) (blame)
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
namespace IOL.GreatOffice.Api.Models.Database;

/// <summary>
/// Base class for all entities with ownership.
/// </summary>
public abstract class BaseWithOwner : Base
{
	protected BaseWithOwner() { }

	protected BaseWithOwner(Guid createdBy)
	{
		CreatedBy = createdBy;
	}

	protected BaseWithOwner(LoggedInUserModel loggedInUser)
	{
		CreatedBy = loggedInUser.Id;
	}

	public Guid? UserId { get; private set; }
	public Guid? TenantId { get; private set; }
	public Guid? ModifiedBy { get; private set; }
	public Guid? CreatedBy { get; private set; }
	public Guid? DeletedBy { get; private set; }
	public User OwningUser { get; set; }
	public Tenant OwningTenant { get; set; }

	public void SetDeleted(Guid userId)
	{
		DeletedBy = userId;
		base.SetDeleted();
	}

	public void SetModified(Guid userId)
	{
		ModifiedBy = userId;
		base.SetModified();
	}

	public void SetOwnerIds(Guid userId = default, Guid tenantId = default)
	{
		if (tenantId != default) TenantId = tenantId;
		if (userId != default) UserId = userId;
	}
}