feat: add network leg position assignment for new users
This commit is contained in:
+23
-1
@@ -1,3 +1,4 @@
|
|||||||
|
using CMSMicroservice.Domain.Enums;
|
||||||
using CMSMicroservice.Domain.Events;
|
using CMSMicroservice.Domain.Events;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
@@ -75,6 +76,26 @@ public class VerifyOtpTokenCommandHandler : IRequestHandler<VerifyOtpTokenComman
|
|||||||
if (await _context.Users.CountAsync(x => x.NetworkParentId == parent.Id, cancellationToken: cancellationToken) > 1)
|
if (await _context.Users.CountAsync(x => x.NetworkParentId == parent.Id, cancellationToken: cancellationToken) > 1)
|
||||||
return new VerifyOtpTokenResponseDto() { Success = false, Message = "ظرفیت معرف تکمیل است!!" };
|
return new VerifyOtpTokenResponseDto() { Success = false, Message = "ظرفیت معرف تکمیل است!!" };
|
||||||
|
|
||||||
|
// تعیین موقعیت در شبکه (چپ یا راست)
|
||||||
|
var existingChildren = await _context.Users
|
||||||
|
.Where(x => x.NetworkParentId == parent.Id && !x.IsDeleted)
|
||||||
|
.Select(x => x.LegPosition)
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
|
NetworkLeg newUserLegPosition;
|
||||||
|
if (!existingChildren.Any(x => x == NetworkLeg.Left))
|
||||||
|
{
|
||||||
|
newUserLegPosition = NetworkLeg.Left;
|
||||||
|
}
|
||||||
|
else if (!existingChildren.Any(x => x == NetworkLeg.Right))
|
||||||
|
{
|
||||||
|
newUserLegPosition = NetworkLeg.Right;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new VerifyOtpTokenResponseDto() { Success = false, Message = "ظرفیت معرف تکمیل است!!" };
|
||||||
|
}
|
||||||
|
|
||||||
user = new User
|
user = new User
|
||||||
{
|
{
|
||||||
Mobile = mobile,
|
Mobile = mobile,
|
||||||
@@ -83,7 +104,8 @@ public class VerifyOtpTokenCommandHandler : IRequestHandler<VerifyOtpTokenComman
|
|||||||
MobileVerifiedAt = now,
|
MobileVerifiedAt = now,
|
||||||
IsRulesAccepted = true,
|
IsRulesAccepted = true,
|
||||||
RulesAcceptedAt = now,
|
RulesAcceptedAt = now,
|
||||||
NetworkParentId = parent.Id
|
NetworkParentId = parent.Id,
|
||||||
|
LegPosition = newUserLegPosition
|
||||||
};
|
};
|
||||||
await _context.Users.AddAsync(user, cancellationToken);
|
await _context.Users.AddAsync(user, cancellationToken);
|
||||||
user.AddDomainEvent(new CreateNewUserEvent(user));
|
user.AddDomainEvent(new CreateNewUserEvent(user));
|
||||||
|
|||||||
+3647
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,22 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class u18 : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user