initial commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class CreateProgramManagerRequest
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public ProgramManagerStatus Status { get; set; }
|
||||
public ProgramManagerPriority Priority { get; set; }
|
||||
public string? ProgramManagerResourceId { get; set; }
|
||||
}
|
||||
|
||||
public class CreateProgramManagerResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
}
|
||||
|
||||
public record CreateProgramManagerCommand(CreateProgramManagerRequest Data) : IRequest<CreateProgramManagerResponse>;
|
||||
|
||||
public class CreateProgramManagerHandler : IRequestHandler<CreateProgramManagerCommand, CreateProgramManagerResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public CreateProgramManagerHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<CreateProgramManagerResponse> Handle(CreateProgramManagerCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = new Data.Entities.ProgramManager
|
||||
{
|
||||
Title = request.Data.Title,
|
||||
Summary = request.Data.Summary,
|
||||
Status = request.Data.Status,
|
||||
Priority = request.Data.Priority,
|
||||
ProgramManagerResourceId = request.Data.ProgramManagerResourceId
|
||||
};
|
||||
|
||||
_context.ProgramManager.Add(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new CreateProgramManagerResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Title = entity.Title
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class CreateProgramManagerValidator : AbstractValidator<CreateProgramManagerRequest>
|
||||
{
|
||||
public CreateProgramManagerValidator()
|
||||
{
|
||||
RuleFor(x => x.Title).NotEmpty().MaximumLength(GlobalConsts.StringLengthMedium);
|
||||
RuleFor(x => x.ProgramManagerResourceId).NotEmpty().WithMessage("Resource is required");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public record DeleteProgramManagerCommand(string Id) : IRequest<bool>;
|
||||
|
||||
public class DeleteProgramManagerHandler : IRequestHandler<DeleteProgramManagerCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public DeleteProgramManagerHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(DeleteProgramManagerCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.ProgramManager
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
_context.ProgramManager.Remove(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class GetProgramManagerByIdResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public ProgramManagerStatus Status { get; set; }
|
||||
public ProgramManagerPriority Priority { get; set; }
|
||||
public string? ProgramManagerResourceId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetProgramManagerByIdQuery(string Id) : IRequest<GetProgramManagerByIdResponse?>;
|
||||
|
||||
public class GetProgramManagerByIdHandler : IRequestHandler<GetProgramManagerByIdQuery, GetProgramManagerByIdResponse?>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetProgramManagerByIdHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<GetProgramManagerByIdResponse?> Handle(GetProgramManagerByIdQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.ProgramManager
|
||||
.AsNoTracking()
|
||||
.Where(x => x.Id == request.Id)
|
||||
.Select(x => new GetProgramManagerByIdResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
Summary = x.Summary,
|
||||
Status = x.Status,
|
||||
Priority = x.Priority,
|
||||
ProgramManagerResourceId = x.ProgramManagerResourceId,
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class GetProgramManagerListResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? AutoNumber { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? ResourceName { get; set; }
|
||||
public string? Status { get; set; }
|
||||
public string? Priority { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public record GetProgramManagerListQuery() : IRequest<List<GetProgramManagerListResponse>>;
|
||||
|
||||
public class GetProgramManagerListHandler : IRequestHandler<GetProgramManagerListQuery, List<GetProgramManagerListResponse>>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetProgramManagerListHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<List<GetProgramManagerListResponse>> Handle(GetProgramManagerListQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
return await _context.ProgramManager
|
||||
.AsNoTracking()
|
||||
.Include(x => x.ProgramManagerResource)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(x => new GetProgramManagerListResponse
|
||||
{
|
||||
Id = x.Id,
|
||||
AutoNumber = x.AutoNumber,
|
||||
Title = x.Title,
|
||||
ResourceName = x.ProgramManagerResource != null ? x.ProgramManagerResource.Name : string.Empty,
|
||||
Status = x.Status.GetDescription(),
|
||||
Priority = x.Priority.GetDescription(),
|
||||
CreatedAt = x.CreatedAt,
|
||||
CreatedBy = x.CreatedBy,
|
||||
UpdatedAt = x.UpdatedAt,
|
||||
UpdatedBy = x.UpdatedBy
|
||||
})
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Indotalent.ConfigBackEnd.Extensions;
|
||||
using Indotalent.Data.Enums;
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class ProgramManagerLookupResponse
|
||||
{
|
||||
public List<LookupItem> Resources { get; set; } = new();
|
||||
public List<LookupItem> Statuses { get; set; } = new();
|
||||
public List<LookupItem> Priorities { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public int Value { get; set; }
|
||||
}
|
||||
|
||||
public record GetProgramManagerLookupQuery() : IRequest<ProgramManagerLookupResponse>;
|
||||
|
||||
public class GetProgramManagerLookupHandler : IRequestHandler<GetProgramManagerLookupQuery, ProgramManagerLookupResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public GetProgramManagerLookupHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<ProgramManagerLookupResponse> Handle(GetProgramManagerLookupQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = new ProgramManagerLookupResponse();
|
||||
|
||||
response.Resources = await _context.ProgramManagerResource
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
response.Statuses = Enum.GetValues(typeof(ProgramManagerStatus))
|
||||
.Cast<ProgramManagerStatus>()
|
||||
.Select(e => new LookupItem { Value = (int)e, Name = e.GetDescription() })
|
||||
.ToList();
|
||||
|
||||
response.Priorities = Enum.GetValues(typeof(ProgramManagerPriority))
|
||||
.Cast<ProgramManagerPriority>()
|
||||
.Select(e => new LookupItem { Value = (int)e, Name = e.GetDescription() })
|
||||
.ToList();
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Indotalent.Data.Enums;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class UpdateProgramManagerRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Title { get; set; }
|
||||
public string? Summary { get; set; }
|
||||
public ProgramManagerStatus Status { get; set; }
|
||||
public ProgramManagerPriority Priority { get; set; }
|
||||
public string? ProgramManagerResourceId { get; set; }
|
||||
public DateTimeOffset? CreatedAt { get; set; }
|
||||
public string? CreatedBy { get; set; }
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
public string? UpdatedBy { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateProgramManagerResponse
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public bool Success { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateProgramManagerCommand(UpdateProgramManagerRequest Data) : IRequest<UpdateProgramManagerResponse>;
|
||||
|
||||
public class UpdateProgramManagerHandler : IRequestHandler<UpdateProgramManagerCommand, UpdateProgramManagerResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public UpdateProgramManagerHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<UpdateProgramManagerResponse> Handle(UpdateProgramManagerCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.ProgramManager
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return new UpdateProgramManagerResponse { Id = request.Data.Id, Success = false };
|
||||
}
|
||||
|
||||
entity.Title = request.Data.Title;
|
||||
entity.Summary = request.Data.Summary;
|
||||
entity.Status = request.Data.Status;
|
||||
entity.Priority = request.Data.Priority;
|
||||
entity.ProgramManagerResourceId = request.Data.ProgramManagerResourceId;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return new UpdateProgramManagerResponse
|
||||
{
|
||||
Id = entity.Id,
|
||||
Success = true
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using FluentValidation;
|
||||
using Indotalent.Shared.Consts;
|
||||
|
||||
namespace Indotalent.Features.Utilities.ProgramManager.Cqrs;
|
||||
|
||||
public class UpdateProgramManagerValidator : AbstractValidator<UpdateProgramManagerRequest>
|
||||
{
|
||||
public UpdateProgramManagerValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.Title).NotEmpty().MaximumLength(GlobalConsts.StringLengthMedium);
|
||||
RuleFor(x => x.ProgramManagerResourceId).NotEmpty().WithMessage("Resource is required");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user