complete login response and user services
parent
80d4467c24
commit
4a775c9373
|
@ -24,7 +24,7 @@ public class ShiftController : ICarterModule
|
|||
group.MapPut("", Put)
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
group.MapDelete("", Delete)
|
||||
group.MapDelete("{id}", Delete)
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
|
||||
|
|
|
@ -19,6 +19,14 @@ public class UserController : ICarterModule
|
|||
.WithDisplayName("GetOneUser")
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
group.MapGet("/profile", GetUserProfileAsync)
|
||||
.WithDisplayName("GetUserProfile")
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
group.MapGet("/profile/role", GetUserProfileAsync)
|
||||
.WithDisplayName("GetUserProfileRoles")
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
group.MapPost("", Post)
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
|
@ -29,6 +37,9 @@ public class UserController : ICarterModule
|
|||
.HasApiVersion(1.0);
|
||||
}
|
||||
|
||||
public async Task<IResult> GetUserProfileAsync(IUserService userService, CancellationToken cancellationToken)
|
||||
=> TypedResults.Ok(await userService.GetUserProfileAsync(cancellationToken));
|
||||
|
||||
// GET:Get All Entity
|
||||
public async Task<IResult> GetAllAsync([FromQuery]int page, IUserService userService, CancellationToken cancellationToken)
|
||||
=> TypedResults.Ok(await userService.GetUsersAsync(page,cancellationToken));
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
namespace Brizco.Core.CoreServices;
|
||||
using Brizco.Domain.Entities.Complex;
|
||||
using Brizco.Domain.Mappers;
|
||||
|
||||
namespace Brizco.Core.CoreServices;
|
||||
|
||||
public class AccountService : IAccountService
|
||||
{
|
||||
|
@ -154,25 +157,58 @@ public class AccountService : IAccountService
|
|||
|
||||
private async Task<AccessToken<ApplicationUserSDto>> CompleteLogin(ApplicationUser user, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var complexUsers = await _repositoryWrapper.SetRepository<ComplexUser>()
|
||||
.TableNoTracking
|
||||
.Where(mcu => mcu.UserId == user.Id)
|
||||
.OrderByDescending(o => o.CreatedAt)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
if(complexUsers == null)
|
||||
return await _jwtService.Generate<ApplicationUserSDto, ApplicationUser>(user);
|
||||
|
||||
var complexUserRoles = await _repositoryWrapper.SetRepository<ComplexUserRole>()
|
||||
.TableNoTracking
|
||||
.Where(c=>c.ComplexUserId==complexUsers.Id)
|
||||
.OrderByDescending(o => o.CreatedAt)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
AccessToken<ApplicationUserSDto> jwt;
|
||||
if (complexUserRoles != null)
|
||||
jwt = await _jwtService.Generate<ApplicationUserSDto, ApplicationUser>(user, complexUsers.ComplexId, complexUserRoles.RoleId);
|
||||
if (user.SelectedComplexUserRoleId != Guid.Empty)
|
||||
{
|
||||
var complexUserRole = await _repositoryWrapper.SetRepository<ComplexUserRole>()
|
||||
.TableNoTracking
|
||||
.Where(c => c.Id == user.SelectedComplexUserRoleId)
|
||||
.Select(ComplexUserRoleMapper.ProjectToSDto)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
var complexUser = await _repositoryWrapper.SetRepository<ComplexUser>()
|
||||
.TableNoTracking
|
||||
.Where(c => c.Id == complexUserRole!.ComplexUserId)
|
||||
.Select(ComplexUserMapper.ProjectToSDto)
|
||||
.FirstOrDefaultAsync( cancellationToken);
|
||||
|
||||
jwt = await _jwtService.Generate<ApplicationUserSDto, ApplicationUser>(user, complexUser!.ComplexId, complexUserRole!.RoleId);
|
||||
jwt.User.SelectedComplexName = complexUser.ComplexName;
|
||||
jwt.User.SelectedRoleName = complexUserRole.RoleName;
|
||||
}
|
||||
else
|
||||
jwt = await _jwtService.Generate<ApplicationUserSDto, ApplicationUser>(user);
|
||||
{
|
||||
var complexUser = await _repositoryWrapper.SetRepository<ComplexUser>()
|
||||
.TableNoTracking
|
||||
.Where(mcu => mcu.UserId == user.Id)
|
||||
.OrderByDescending(o => o.CreatedAt)
|
||||
.Select(ComplexUserMapper.ProjectToSDto)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
if (complexUser == null)
|
||||
return await _jwtService.Generate<ApplicationUserSDto, ApplicationUser>(user);
|
||||
|
||||
var complexUserRole = await _repositoryWrapper.SetRepository<ComplexUserRole>()
|
||||
.TableNoTracking
|
||||
.Where(c => c.ComplexUserId == complexUser.Id)
|
||||
.OrderByDescending(o => o.CreatedAt)
|
||||
.Select(ComplexUserRoleMapper.ProjectToSDto)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
|
||||
|
||||
if (complexUserRole != null)
|
||||
{
|
||||
|
||||
user.SelectedComplexUserRoleId = complexUserRole.Id;
|
||||
await _userManager.UpdateAsync(user);
|
||||
jwt = await _jwtService.Generate<ApplicationUserSDto, ApplicationUser>(user, complexUser.ComplexId, complexUserRole.RoleId);
|
||||
jwt.User.SelectedComplexName = complexUser.ComplexName;
|
||||
jwt.User.SelectedRoleName = complexUserRole.RoleName;
|
||||
}
|
||||
else
|
||||
jwt = await _jwtService.Generate<ApplicationUserSDto, ApplicationUser>(user);
|
||||
|
||||
}
|
||||
|
||||
return jwt;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
public interface IUserService : IScopedDependency
|
||||
{
|
||||
Task<ApplicationUserSDto> GetUserProfileAsync(CancellationToken cancellationToken);
|
||||
Task<List<ComplexUserRoleSDto>> GetUserRolesAsync(CancellationToken cancellationToken);
|
||||
Task<List<ComplexUserSDto>> GetUsersAsync(int page = 0, CancellationToken cancellationToken = default);
|
||||
Task<ApplicationUserSDto> GetUserAsync(Guid userId);
|
||||
Task<ApplicationUser> CreateUserAsync(string phoneNumber);
|
||||
|
|
|
@ -27,6 +27,69 @@ public class UserService : IUserService
|
|||
_repositoryWrapper = repositoryWrapper;
|
||||
}
|
||||
|
||||
|
||||
public async Task<ApplicationUserSDto> GetUserProfileAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (!Guid.TryParse(_currentUserService.UserId, out var userId))
|
||||
throw new AppException("Wrong Token", ApiResultStatusCode.UnAuthorized);
|
||||
var user = await _userManager.FindByIdAsync(userId.ToString());
|
||||
if (user == null)
|
||||
throw new AppException("User NotFound", ApiResultStatusCode.NotFound);
|
||||
var response = user.AdaptToSDto();
|
||||
|
||||
if (user.SelectedComplexUserRoleId != Guid.Empty)
|
||||
{
|
||||
var complexUserRole = await _repositoryWrapper.SetRepository<ComplexUserRole>()
|
||||
.TableNoTracking
|
||||
.Where(c => c.Id == user.SelectedComplexUserRoleId)
|
||||
.Select(ComplexUserRoleMapper.ProjectToSDto)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
var complexUser = await _repositoryWrapper.SetRepository<ComplexUser>()
|
||||
.TableNoTracking
|
||||
.Where(c => c.Id == complexUserRole!.ComplexUserId)
|
||||
.Select(ComplexUserMapper.ProjectToSDto)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
response.SelectedComplexName = complexUser!.ComplexName;
|
||||
response.SelectedRoleName = complexUserRole!.RoleName;
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public async Task<List<ComplexUserRoleSDto>> GetUserRolesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (!Guid.TryParse(_currentUserService.UserId, out var userId))
|
||||
throw new AppException("Wrong Token", ApiResultStatusCode.UnAuthorized);
|
||||
var user = await _userManager.FindByIdAsync(userId.ToString());
|
||||
if (user == null)
|
||||
throw new AppException("User NotFound", ApiResultStatusCode.NotFound);
|
||||
var response = new List<ComplexUserRoleSDto>();
|
||||
var complexUsers = await _repositoryWrapper.SetRepository<ComplexUser>()
|
||||
.TableNoTracking
|
||||
.Where(mcu => mcu.UserId == user.Id)
|
||||
.Select(ComplexUserMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken);
|
||||
if (complexUsers.Count == 0)
|
||||
return response;
|
||||
|
||||
foreach (var complexUser in complexUsers)
|
||||
{
|
||||
var complexUserRoles = await _repositoryWrapper.SetRepository<ComplexUserRole>()
|
||||
.TableNoTracking
|
||||
.Where(c => c.ComplexUserId == complexUser.Id)
|
||||
.Select(ComplexUserRoleMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken);
|
||||
foreach (var userRole in complexUserRoles)
|
||||
{
|
||||
userRole.ComplexName = complexUser.ComplexName;
|
||||
response.Add(userRole);
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
public async Task<List<ComplexUserSDto>> GetUsersAsync(int page = 0, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_currentUserService.ComplexId.IsNullOrEmpty())
|
||||
|
|
|
@ -67,7 +67,6 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Folder Include="Dtos\LargDtos\" />
|
||||
<Folder Include="Dtos\ResponseDto\" />
|
||||
<Folder Include="Dtos\RequestDtos\" />
|
||||
<Folder Include="Models\Settings\" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Brizco.Domain.CommandQueries.Commands;
|
||||
|
||||
public sealed record CreateShiftCommand(string Title, TimeSpan StartAt, TimeSpan EndAt, string Description , List<DayOfWeek> DayOfWeeks)
|
||||
: IRequest<Shift>;
|
||||
: IRequest<ShiftSDto>;
|
||||
|
||||
public sealed record UpdateShiftCommand(Guid Id,string Title, TimeSpan StartAt, TimeSpan EndAt, string Description, List<DayOfWeek> DayOfWeeks)
|
||||
: IRequest<bool>;
|
||||
|
|
|
@ -7,8 +7,6 @@ public class ComplexUserRoleSDto : BaseDto<ComplexUserRoleSDto,ComplexUserRole>
|
|||
public Guid RoleId { get; set; }
|
||||
public Guid ComplexUserId { get; set; }
|
||||
|
||||
|
||||
public Guid UserId { get; set; }
|
||||
public Guid ComplexId { get; set; }
|
||||
|
||||
public string RoleName { get; set; } = string.Empty;
|
||||
public string ComplexName { get; set; } = string.Empty;
|
||||
}
|
|
@ -7,6 +7,9 @@ public class ApplicationUser : IdentityUser<Guid>
|
|||
public string FirstName { get; set; } = string.Empty;
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
public string NationalId { get; set; } = string.Empty;
|
||||
|
||||
public Guid SelectedComplexUserRoleId { get; set; }
|
||||
|
||||
public DateTime BirthDate { get; set; }
|
||||
public Gender Gender { get; set; }
|
||||
public SignUpStatus SignUpStatus { get; set; }
|
||||
|
|
|
@ -2,6 +2,8 @@ using System;
|
|||
using System.Linq.Expressions;
|
||||
using Brizco.Domain.Dtos.SmallDtos;
|
||||
using Brizco.Domain.Entities.Complex;
|
||||
using Brizco.Domain.Entities.User;
|
||||
using Mapster.Models;
|
||||
|
||||
namespace Brizco.Domain.Mappers
|
||||
{
|
||||
|
@ -12,7 +14,13 @@ namespace Brizco.Domain.Mappers
|
|||
return p1 == null ? null : new ComplexUserRole()
|
||||
{
|
||||
ComplexUserId = p1.ComplexUserId,
|
||||
ComplexUser = new ComplexUser() {Id = p1.ComplexUserId},
|
||||
RoleId = p1.RoleId,
|
||||
Role = new ApplicationRole()
|
||||
{
|
||||
Id = p1.RoleId,
|
||||
Name = p1.RoleName
|
||||
},
|
||||
Id = p1.Id
|
||||
};
|
||||
}
|
||||
|
@ -25,45 +33,75 @@ namespace Brizco.Domain.Mappers
|
|||
ComplexUserRole result = p3 ?? new ComplexUserRole();
|
||||
|
||||
result.ComplexUserId = p2.ComplexUserId;
|
||||
result.ComplexUser = funcMain1(new Never(), result.ComplexUser, p2);
|
||||
result.RoleId = p2.RoleId;
|
||||
result.Role = funcMain2(new Never(), result.Role, p2);
|
||||
result.Id = p2.Id;
|
||||
return result;
|
||||
|
||||
}
|
||||
public static Expression<Func<ComplexUserRoleSDto, ComplexUserRole>> ProjectToComplexUserRole => p4 => new ComplexUserRole()
|
||||
public static Expression<Func<ComplexUserRoleSDto, ComplexUserRole>> ProjectToComplexUserRole => p8 => new ComplexUserRole()
|
||||
{
|
||||
ComplexUserId = p4.ComplexUserId,
|
||||
RoleId = p4.RoleId,
|
||||
Id = p4.Id
|
||||
};
|
||||
public static ComplexUserRoleSDto AdaptToSDto(this ComplexUserRole p5)
|
||||
{
|
||||
return p5 == null ? null : new ComplexUserRoleSDto()
|
||||
ComplexUserId = p8.ComplexUserId,
|
||||
ComplexUser = new ComplexUser() {Id = p8.ComplexUserId},
|
||||
RoleId = p8.RoleId,
|
||||
Role = new ApplicationRole()
|
||||
{
|
||||
RoleId = p5.RoleId,
|
||||
ComplexUserId = p5.ComplexUserId,
|
||||
Id = p5.Id
|
||||
Id = p8.RoleId,
|
||||
Name = p8.RoleName
|
||||
},
|
||||
Id = p8.Id
|
||||
};
|
||||
public static ComplexUserRoleSDto AdaptToSDto(this ComplexUserRole p9)
|
||||
{
|
||||
return p9 == null ? null : new ComplexUserRoleSDto()
|
||||
{
|
||||
RoleId = p9.RoleId,
|
||||
ComplexUserId = p9.ComplexUserId,
|
||||
RoleName = p9.Role == null ? null : p9.Role.PersianName,
|
||||
Id = p9.Id
|
||||
};
|
||||
}
|
||||
public static ComplexUserRoleSDto AdaptTo(this ComplexUserRole p6, ComplexUserRoleSDto p7)
|
||||
public static ComplexUserRoleSDto AdaptTo(this ComplexUserRole p10, ComplexUserRoleSDto p11)
|
||||
{
|
||||
if (p6 == null)
|
||||
if (p10 == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ComplexUserRoleSDto result = p7 ?? new ComplexUserRoleSDto();
|
||||
ComplexUserRoleSDto result = p11 ?? new ComplexUserRoleSDto();
|
||||
|
||||
result.RoleId = p6.RoleId;
|
||||
result.ComplexUserId = p6.ComplexUserId;
|
||||
result.Id = p6.Id;
|
||||
result.RoleId = p10.RoleId;
|
||||
result.ComplexUserId = p10.ComplexUserId;
|
||||
result.RoleName = p10.Role == null ? null : p10.Role.PersianName;
|
||||
result.Id = p10.Id;
|
||||
return result;
|
||||
|
||||
}
|
||||
public static Expression<Func<ComplexUserRole, ComplexUserRoleSDto>> ProjectToSDto => p8 => new ComplexUserRoleSDto()
|
||||
public static Expression<Func<ComplexUserRole, ComplexUserRoleSDto>> ProjectToSDto => p12 => new ComplexUserRoleSDto()
|
||||
{
|
||||
RoleId = p8.RoleId,
|
||||
ComplexUserId = p8.ComplexUserId,
|
||||
Id = p8.Id
|
||||
RoleId = p12.RoleId,
|
||||
ComplexUserId = p12.ComplexUserId,
|
||||
RoleName = p12.Role.PersianName,
|
||||
Id = p12.Id
|
||||
};
|
||||
|
||||
private static ComplexUser funcMain1(Never p4, ComplexUser p5, ComplexUserRoleSDto p2)
|
||||
{
|
||||
ComplexUser result = p5 ?? new ComplexUser();
|
||||
|
||||
result.Id = p2.ComplexUserId;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private static ApplicationRole funcMain2(Never p6, ApplicationRole p7, ComplexUserRoleSDto p2)
|
||||
{
|
||||
ApplicationRole result = p7 ?? new ApplicationRole();
|
||||
|
||||
result.Id = p2.RoleId;
|
||||
result.Name = p2.RoleName;
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -63,7 +63,7 @@ namespace Brizco.Domain.Mappers
|
|||
Description = p11.Description,
|
||||
StartAt = p11.StartAt,
|
||||
EndAt = p11.EndAt,
|
||||
Days = funcMain4(p11.Days != null ? p11.Days.Select<ShiftDay, DayOfWeek>(funcMain5).ToList<DayOfWeek>() : new List<DayOfWeek>()),
|
||||
Days = funcMain4(p11.Days.Select<ShiftDay, DayOfWeek>(funcMain5).ToList<DayOfWeek>()),
|
||||
ComplexId = p11.ComplexId,
|
||||
Id = p11.Id
|
||||
};
|
||||
|
@ -80,7 +80,7 @@ namespace Brizco.Domain.Mappers
|
|||
result.Description = p13.Description;
|
||||
result.StartAt = p13.StartAt;
|
||||
result.EndAt = p13.EndAt;
|
||||
result.Days = funcMain6(p13.Days != null ? p13.Days.Select<ShiftDay, DayOfWeek>(funcMain5).ToList<DayOfWeek>() : new List<DayOfWeek>(), result.Days);
|
||||
result.Days = funcMain6(p13.Days.Select<ShiftDay, DayOfWeek>(funcMain5).ToList<DayOfWeek>(), result.Days);
|
||||
result.ComplexId = p13.ComplexId;
|
||||
result.Id = p13.Id;
|
||||
return result;
|
||||
|
@ -92,7 +92,7 @@ namespace Brizco.Domain.Mappers
|
|||
Description = p17.Description,
|
||||
StartAt = p17.StartAt,
|
||||
EndAt = p17.EndAt,
|
||||
Days = p17.Days != null ? p17.Days.Select<ShiftDay, DayOfWeek>(d => d.DayOfWeek).ToList<DayOfWeek>() : new List<DayOfWeek>(),
|
||||
Days = p17.Days.Select<ShiftDay, DayOfWeek>(d => d.DayOfWeek).ToList<DayOfWeek>(),
|
||||
ComplexId = p17.ComplexId,
|
||||
Id = p17.Id
|
||||
};
|
||||
|
|
|
@ -9,7 +9,12 @@ public class MapsterRegister : IRegister
|
|||
public void Register(TypeAdapterConfig config)
|
||||
{
|
||||
config.NewConfig<Shift, ShiftSDto>()
|
||||
.Map("Days", org => org.Days != null ? org.Days.Select(d=>d.DayOfWeek).ToList() : new List<DayOfWeek>())
|
||||
.Map("Days", org => org.Days.Select(d=>d.DayOfWeek).ToList())
|
||||
.TwoWays();
|
||||
|
||||
|
||||
config.NewConfig<ComplexUserRole, ComplexUserRoleSDto>()
|
||||
.Map("RoleName", org => org.Role!.PersianName)
|
||||
.TwoWays();
|
||||
|
||||
config.NewConfig<ComplexUser, ComplexUserSDto>()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
namespace Brizco.Repository.Handlers.Shift;
|
||||
|
||||
public class CreateShiftCommandHandler : IRequestHandler<CreateShiftCommand, Domain.Entities.Shift.Shift>
|
||||
public class CreateShiftCommandHandler : IRequestHandler<CreateShiftCommand, ShiftSDto>
|
||||
{
|
||||
private readonly IRepositoryWrapper _repositoryWrapper;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
|
@ -10,7 +10,7 @@ public class CreateShiftCommandHandler : IRequestHandler<CreateShiftCommand, Dom
|
|||
_repositoryWrapper = repositoryWrapper;
|
||||
_currentUserService = currentUserService;
|
||||
}
|
||||
public async Task<Domain.Entities.Shift.Shift> Handle(CreateShiftCommand request, CancellationToken cancellationToken)
|
||||
public async Task<ShiftSDto> Handle(CreateShiftCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
if (_currentUserService.ComplexId == null)
|
||||
|
@ -33,7 +33,7 @@ public class CreateShiftCommandHandler : IRequestHandler<CreateShiftCommand, Dom
|
|||
_repositoryWrapper.SetRepository<Domain.Entities.Shift.Shift>().Add(shift);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
await _repositoryWrapper.CommitAsync(cancellationToken);
|
||||
return shift;
|
||||
return shift.AdaptToSDto();
|
||||
}
|
||||
catch (Exception )
|
||||
{
|
||||
|
|
|
@ -16,6 +16,11 @@ public class GetShiftPlansQueryHandler : IRequestHandler<GetShiftsQuery, List<Sh
|
|||
.Select(ShiftMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
shifts.ForEach(s =>
|
||||
{
|
||||
s.Days = s.Days.OrderBy(d=>d).ToList();
|
||||
});
|
||||
|
||||
return shifts;
|
||||
}
|
||||
}
|
|
@ -1,11 +1,13 @@
|
|||
namespace Brizco.Repository.Handlers.Shift;
|
||||
using Brizco.Domain.Entities.Shift;
|
||||
|
||||
namespace Brizco.Repository.Handlers.Shift;
|
||||
|
||||
public class UpdateShiftCommandHandler : IRequestHandler<UpdateShiftCommand, bool>
|
||||
{
|
||||
private readonly IRepositoryWrapper _repositoryWrapper;
|
||||
private readonly ICurrentUserService _currentUserService;
|
||||
|
||||
public UpdateShiftCommandHandler(IRepositoryWrapper repositoryWrapper,ICurrentUserService currentUserService)
|
||||
public UpdateShiftCommandHandler(IRepositoryWrapper repositoryWrapper, ICurrentUserService currentUserService)
|
||||
{
|
||||
_repositoryWrapper = repositoryWrapper;
|
||||
_currentUserService = currentUserService;
|
||||
|
@ -14,7 +16,7 @@ public class UpdateShiftCommandHandler : IRequestHandler<UpdateShiftCommand, boo
|
|||
public async Task<bool> Handle(UpdateShiftCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var shift = await _repositoryWrapper.SetRepository<Domain.Entities.Shift.Shift>()
|
||||
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id);
|
||||
.TableNoTracking.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
|
||||
if (shift == null)
|
||||
throw new AppException("Shift not found", ApiResultStatusCode.NotFound);
|
||||
|
||||
|
@ -29,6 +31,26 @@ public class UpdateShiftCommandHandler : IRequestHandler<UpdateShiftCommand, boo
|
|||
request.EndAt,
|
||||
complexId);
|
||||
newShift.Id = request.Id;
|
||||
|
||||
var shiftDays = await _repositoryWrapper.SetRepository<ShiftDay>()
|
||||
.TableNoTracking.Where(sd => sd.ShiftId == request.Id)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
foreach (var shiftDay in shiftDays.Where(shiftDay => !request.DayOfWeeks.Contains(shiftDay.DayOfWeek)))
|
||||
{
|
||||
_repositoryWrapper.SetRepository<ShiftDay>()
|
||||
.Delete(shiftDay);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
foreach (var dayOfWeek in request.DayOfWeeks)
|
||||
{
|
||||
var findDay = shiftDays.FirstOrDefault(sf => sf.DayOfWeek == dayOfWeek);
|
||||
if (findDay != null)
|
||||
shift.SetDay(dayOfWeek);
|
||||
}
|
||||
|
||||
|
||||
_repositoryWrapper.SetRepository<Domain.Entities.Shift.Shift>()
|
||||
.Update(newShift);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,32 @@
|
|||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Brizco.Repository.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class editUser : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<Guid>(
|
||||
name: "SelectedComplexUserRoleId",
|
||||
schema: "public",
|
||||
table: "Users",
|
||||
type: "uuid",
|
||||
nullable: false,
|
||||
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "SelectedComplexUserRoleId",
|
||||
schema: "public",
|
||||
table: "Users");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -717,6 +717,9 @@ namespace Brizco.Repository.Migrations
|
|||
b.Property<string>("SecurityStamp")
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<Guid>("SelectedComplexUserRoleId")
|
||||
.HasColumnType("uuid");
|
||||
|
||||
b.Property<int>("SignUpStatus")
|
||||
.HasColumnType("integer");
|
||||
|
||||
|
|
Loading…
Reference in New Issue