Commit bca956a3 authored by hasan khaddour's avatar hasan khaddour

fix s.

parent 5e095f70
......@@ -18,6 +18,7 @@ using PSManagement.Contracts.Customers.Responses;
using PSManagement.Application.Customers.UseCases.Queries.GetCustomer;
using PSManagement.Api.Controllers.ApiBase;
using Ardalis.Result;
using PSManagement.Application.Customers.UseCases.Commands.RemoveContactInfo;
namespace PSManagement.Api.Controllers.Customers
{
......@@ -35,36 +36,53 @@ namespace PSManagement.Api.Controllers.Customers
}
[HttpGet]
public async Task<IActionResult> ListCustomers()
public async Task<IActionResult> Get()
{
var query = new ListAllCustomersQuery();
var result = _mapper.Map<Result<IEnumerable<CustomerRecord>>>( await _sender.Send(query));
var result = _mapper.Map<Result<IEnumerable<CustomerResponse>>>( await _sender.Send(query));
return Ok(result);
}
[HttpGet("{id}")]
public async Task<IActionResult> GetCustomer(int id )
public async Task<IActionResult> Get(int id )
{
var query = new GetCustomerQuery(id);
var result = await _sender.Send(query);
return Ok(_mapper.Map<Result<CustomerRecord>>(result));
return Ok(_mapper.Map<Result<CustomerResponse>>(result));
}
[HttpPost]
public async Task<IActionResult> CreateCustomer(CreateCustomerRequest request)
public async Task<IActionResult> Post(CreateCustomerRequest request)
{
var command = _mapper.Map<CreateCustomerCommand>(request);
var result = await _sender.Send(command);
return Ok(result);
if (result.IsSuccess)
{
var query = new GetCustomerQuery(result.Value);
var response = await _sender.Send(query);
return Ok(_mapper.Map<CustomerResponse>(response));
}
else
{
return Ok(result);
}
}
[HttpDelete]
public async Task<IActionResult> DeleteCustomer(DeleteCustomerRequest request)
public async Task<IActionResult> Delete(DeleteCustomerRequest request)
{
var command = _mapper.Map<DeleteCustomerCommand>(request);
......@@ -73,8 +91,9 @@ namespace PSManagement.Api.Controllers.Customers
return Ok(result);
}
[HttpPut("{id}")]
public async Task<IActionResult> UpdateCustomer(int id ,UpdateCustomerRequest request)
public async Task<IActionResult> Put(int id ,UpdateCustomerRequest request)
{
if(id != request.CustomerId){
return Problem();
......@@ -89,7 +108,7 @@ namespace PSManagement.Api.Controllers.Customers
[HttpPost("AddContactInfo")]
public async Task<IActionResult> AddContactInfo(AddContactInfoRequest request)
public async Task<IActionResult> PostContactInfo(AddContactInfoRequest request)
{
var command = _mapper.Map<AddContactInfoCommand>(request);
......@@ -99,6 +118,16 @@ namespace PSManagement.Api.Controllers.Customers
}
[HttpDelete("RemoveContactInfo")]
public async Task<IActionResult> DeleteContactInfo(RemoveContactInfoRequest request)
{
var command = _mapper.Map<RemoveContactInfoCommand>(request);
var result = await _sender.Send(command);
return Ok(result);
}
}
}
......@@ -32,12 +32,12 @@ namespace PSManagement.Api.Mappers
CreateMap<UpdateCustomerCommand, UpdateCustomerRequest>().ReverseMap();
CreateMap<AddContactInfoRequest, AddContactInfoCommand>().ReverseMap();
CreateMap<CustomerDTO, CustomerRecord>();
CreateMap<ContactInfoDTO, ContactInfoRecord>();
CreateMap<CustomerDTO, CustomerResponse>();
CreateMap<ContactInfoDTO, ContactInfoResponse>();
CreateMap<CustomerRecord, CustomerDTO>().ReverseMap();
CreateMap<CustomerResponse, CustomerDTO>().ReverseMap();
CreateMap<IEnumerable<CustomerRecord>, ListCustomersResponse>()
CreateMap<IEnumerable<CustomerResponse>, ListCustomersResponse>()
.ConstructUsing(src => new ListCustomersResponse(src));
}
......
......@@ -13,7 +13,7 @@ namespace PSManagement.Application.Behaviors.ValidationBehavior
{
public class ValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : IRequest<TResponse>
where TRequest : IRequest<TResponse>
{
private readonly IEnumerable<IValidator<TRequest>> _validators;
......@@ -23,8 +23,9 @@ namespace PSManagement.Application.Behaviors.ValidationBehavior
}
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{
if (_validators is null) {
{
if (_validators is null)
{
return await next();
}
......@@ -34,7 +35,7 @@ namespace PSManagement.Application.Behaviors.ValidationBehavior
var errors = validationResults.SelectMany(r => r.Errors)
.Where(e => e != null)
.Select(e => new ValidationError(e.ErrorCode,e.ErrorMessage,e.ErrorCode,new ValidationSeverity()))
.Select(e => new ValidationError(e.ErrorCode, e.ErrorMessage, e.ErrorCode, new ValidationSeverity()))
.ToList();
if (errors.Any())
......@@ -45,28 +46,5 @@ namespace PSManagement.Application.Behaviors.ValidationBehavior
return await next();
}
private Result ValidateAsync(TRequest request)
{
var context = new ValidationContext<TRequest>(request);
var failures = _validators
.Select(v => v.Validate(context))
.SelectMany(result => result.Errors)
.Where(f => f != null)
.ToList();
if (failures.Count != 0)
{
var result = Result.Invalid(new ValidationError("validation Error."));
//foreach (var failure in failures)
//{
// result.Reasons.Add(new Error(failure.ErrorMessage));
//}
return result;
}
return Result.Success();
}
}
}
using PSManagement.Domain.Customers.DomainEvents;
using Microsoft.Extensions.Logging;
using PSManagement.Application.Contracts.Providers;
using PSManagement.Domain.Customers.DomainEvents;
using PSManagement.Domain.Customers.Entities;
using PSManagement.SharedKernel.DomainEvents;
using System;
using System.Collections.Generic;
......@@ -11,10 +14,22 @@ namespace PSManagement.Application.Customers.Events
{
public class CustomerCreatedEventHandler : IDomainEventHandler<CutsomerCreatedEvent>
{
private readonly ILogger<Customer> _logger;
private readonly IDateTimeProvider _dateTimeProvider;
public CustomerCreatedEventHandler(
ILogger<Customer> logger,
IDateTimeProvider dateTimeProvider)
{
_logger = logger;
_dateTimeProvider = dateTimeProvider;
}
public Task Handle(CutsomerCreatedEvent notification, CancellationToken cancellationToken)
{
Console.WriteLine("fdgfg");
_logger.LogInformation("new customer Added at "+_dateTimeProvider.UtcNow);
return Task.CompletedTask;
}
......
using Ardalis.Result;
using PSManagement.SharedKernel.CQRS.Command;
namespace PSManagement.Application.Customers.UseCases.Commands.RemoveContactInfo
{
public record RemoveContactInfoCommand(
int Id,
int CustomerId) : ICommand<Result>;
}
using Ardalis.Result;
using PSManagement.Domain.Customers.DomainErrors;
using PSManagement.Domain.Customers.Entities;
using PSManagement.Domain.Customers.Repositories;
using PSManagement.SharedKernel.CQRS.Command;
using PSManagement.SharedKernel.Repositories;
using System.Threading;
using System.Threading.Tasks;
namespace PSManagement.Application.Customers.UseCases.Commands.RemoveContactInfo
{
public class RemoveContactInfoCommandHandler : ICommandHandler<RemoveContactInfoCommand, Result>
{
private readonly ICustomersRepository _customersRepository;
private readonly IRepository<ContactInfo> _contactsRepository;
public RemoveContactInfoCommandHandler(
ICustomersRepository customersRepository,
IRepository<ContactInfo> contactsRepository)
{
_customersRepository = customersRepository;
_contactsRepository = contactsRepository;
}
public async Task<Result> Handle(RemoveContactInfoCommand request, CancellationToken cancellationToken)
{
Customer customer = await _customersRepository.GetByIdAsync(request.CustomerId);
if (customer is null)
{
return Result.Invalid(CustomerErrors.InvalidEntryError);
}
ContactInfo contact = await _contactsRepository.GetByIdAsync(request.Id);
if (contact is null) {
return Result.Invalid(CustomerErrors.InvalidEntryError);
}
await _contactsRepository.DeleteAsync(contact);
return Result.Success();
}
}
}
......@@ -27,8 +27,10 @@ namespace PSManagement.Application.Customers.UseCases.Commands.UpdateCustomer
public async Task<Result> Handle(UpdateCustomerCommand request, CancellationToken cancellationToken)
{
Customer customer = new (request.CustomerName ,request.Address,request.Email);
customer.Id = request.CustomerId;
Customer customer = await _customerRepository.GetByIdAsync(request.CustomerId);
customer.Email = request.Email;
customer.CustomerName = request.CustomerName;
customer.Address = request.Address;
await _customerRepository.UpdateAsync(customer);
......
......@@ -7,6 +7,6 @@ using System.Text;
namespace PSManagement.Application.Customers.UseCases.Queries.GetCustomer
{
public record GetCustomerQuery(int customerId) : IQuery<Result<CustomerDTO>>;
public record GetCustomerQuery(int CustomerId) : IQuery<Result<CustomerDTO>>;
}
......@@ -4,7 +4,9 @@ using PSManagement.Application.Customers.Common;
using PSManagement.Domain.Customers.DomainErrors;
using PSManagement.Domain.Customers.Entities;
using PSManagement.Domain.Customers.Repositories;
using PSManagement.Domain.Customers.Specification;
using PSManagement.SharedKernel.CQRS.Query;
using PSManagement.SharedKernel.Specification;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
......@@ -15,18 +17,23 @@ namespace PSManagement.Application.Customers.UseCases.Queries.GetCustomer
{
private readonly ICustomersRepository _customersRepository;
private readonly IMapper _mapper;
private readonly BaseSpecification<Customer> _specification ;
public GetCustomerQueryHandler(ICustomersRepository customersRepository, IMapper mapper)
{
_customersRepository = customersRepository;
_mapper = mapper;
_specification = new CustomerSpecification();
}
public async Task<Result<CustomerDTO>> Handle(GetCustomerQuery request, CancellationToken cancellationToken)
{
Customer customer = await _customersRepository.GetByIdAsync(request.customerId);
Customer customer = await _customersRepository.GetByIdAsync(request.CustomerId,_specification);
if (customer is null) {
return Result.NotFound(CustomerErrors.InvalidEntryError.ErrorMessage);
return Result.Invalid(CustomerErrors.InvalidEntryError);
}
return Result.Success(_mapper.Map<CustomerDTO>(customer));
}
......
......@@ -15,6 +15,7 @@ namespace PSManagement.Application.Employees.Common
public String DepartmentName { get; set; }
public PersonalInfo PersonalInfo { get; set; }
public WorkInfo WorkInfo { get; set; }
public Availability Availability { get; set; }
}
}
......@@ -28,7 +28,7 @@ namespace PSManagement.Application.Employees.UseCases.Queries.GetEmployeeById
public async Task<Result<EmployeeDTO>> Handle(GetEmployeeByIdQuery request, CancellationToken cancellationToken)
{
_specification.AddInclude(e => e.Department);
return Result.Success(_mapper.Map<EmployeeDTO>(await _employeesRepository.GetByIdAsync(request.EmployeeId,_specification)));
}
}
......
......@@ -38,6 +38,8 @@ namespace PSManagement.Application.Employees.UseCases.Queries.GetEmployeeById
_specification.AddInclude("Employee.Department");
_specification.AddInclude(e => e.Employee);
_specification.AddInclude(e => e.Employee.Department);
IEnumerable<EmployeeParticipate> response = await _employeesParticipateRepository.ListAsync(_specification);
......
......@@ -17,21 +17,17 @@ namespace PSManagement.Application.FinancialSpends.UseCases.Commands.CreateFinan
private readonly IProjectsRepository _projectsRepository;
private readonly IFinancialSpendingRepository _spendRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly IMapper _mapper;
public CreateFinancialSpendItemCommandHandler(
IFinancialSpendingRepository spendRepository,
IProjectsRepository projectsRepository,
IUnitOfWork unitOfWork,
IMapper mapper)
IUnitOfWork unitOfWork
)
{
_spendRepository = spendRepository;
_projectsRepository = projectsRepository;
_unitOfWork = unitOfWork;
_mapper = mapper;
}
......
......@@ -7,7 +7,6 @@
<ItemGroup>
<Folder Include="Behaviors\AuthorizationBehavior\" />
<Folder Include="Customers\UseCases\Commands\RemoveContactInfo\" />
<Folder Include="Tracks\EventsHandlers\" />
</ItemGroup>
......
......@@ -41,7 +41,8 @@ namespace PSManagement.Application.Projects.UseCases.Commands.AddParticipant
public async Task<Result> Handle(AddParticipantCommand request, CancellationToken cancellationToken)
{
_specification.Includes.Add(p => p.EmployeeParticipates);
_specification.AddInclude(e => e.EmployeeParticipates);
Project project =await _projectsRepository.GetByIdAsync(request.ProjectId,_specification);
if (project is null)
{
......@@ -54,12 +55,14 @@ namespace PSManagement.Application.Projects.UseCases.Commands.AddParticipant
return Result.Invalid(ProjectsErrors.ParticipantExistError);
}
else {
Employee employee = await _employeesRepository.GetByIdAsync(request.ParticipantId);
if (employee is null) {
return Result.Invalid(EmployeesErrors.EmployeeUnExist);
}
await _employeeParticipateRepository.AddAsync(new (request.ParticipantId,request.ProjectId,request.Role,request.PartialTimeRatio));
project.AddDomainEvent(new ParticipantAddedEvent(request.ParticipantId,request.ProjectId,request.PartialTimeRatio,request.Role));
......
using Ardalis.Result;
using PSManagement.Application.Contracts.Providers;
using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.Entities;
using PSManagement.Domain.Projects.Repositories;
......@@ -13,16 +14,17 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CancelProject
{
private readonly IProjectsRepository _projectsRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly IDateTimeProvider _dateTime;
public CancelProjectCommandHandler(
IProjectsRepository projectsRepository,
IUnitOfWork unitOfWork
)
IUnitOfWork unitOfWork,
IDateTimeProvider dateTime)
{
_projectsRepository = projectsRepository;
_unitOfWork = unitOfWork;
_dateTime = dateTime;
}
public async Task<Result> Handle(CancelProjectCommand request, CancellationToken cancellationToken)
......@@ -35,7 +37,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.CancelProject
else
{
project.Cancle();
project.Cancel(_dateTime.UtcNow);
await _unitOfWork.SaveChangesAsync();
return Result.Success();
......
using Ardalis.Result;
using PSManagement.Domain.Projects;
using PSManagement.Domain.Projects.DomainErrors;
using PSManagement.Domain.Projects.DomainEvents;
using PSManagement.Domain.Projects.Entities;
......@@ -6,6 +7,7 @@ using PSManagement.Domain.Projects.Repositories;
using PSManagement.SharedKernel.CQRS.Command;
using PSManagement.SharedKernel.Interfaces;
using PSManagement.SharedKernel.Repositories;
using PSManagement.SharedKernel.Specification;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
......@@ -17,6 +19,7 @@ namespace PSManagement.Application.Projects.UseCases.Commands.RemoveParticipant
private readonly IProjectsRepository _projectsRepository;
private readonly IRepository<EmployeeParticipate> _employeeParticipateRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly BaseSpecification<Project> _specification;
public AddParticipantCommandHandler(
IRepository<EmployeeParticipate> repository,
......@@ -24,37 +27,41 @@ namespace PSManagement.Application.Projects.UseCases.Commands.RemoveParticipant
IUnitOfWork unitOfWork)
{
_employeeParticipateRepository = repository;
_specification = new ProjectSpecification();
_projectsRepository = projectsRepository;
_unitOfWork = unitOfWork;
}
public async Task<Result> Handle(RemoveParticipantCommand request, CancellationToken cancellationToken)
{
Project project = await _projectsRepository.GetByIdAsync(request.ProjectId);
_specification.AddInclude(e => e.EmployeeParticipates);
Project project = await _projectsRepository.GetByIdAsync(request.ProjectId,_specification);
if (project is null)
{
return Result.Invalid(ProjectsErrors.InvalidEntryError);
}
else
{
if (project.EmployeeParticipates is null) {
if (project.EmployeeParticipates?.Where(e => e.Id == request.ParticipantId) is null)
{
return Result.Invalid(ProjectsErrors.ParticipantUnExistError);
}
var employeeParticipate =project.EmployeeParticipates.Where(e => e.ProjectId == request.ParticipantId).FirstOrDefault();
if (employeeParticipate is null) {
return Result.Invalid(ProjectsErrors.ParticipantUnExistError);
}
else
{
EmployeeParticipate participant = await _employeeParticipateRepository.GetByIdAsync(request.ParticipantId);
await _employeeParticipateRepository.DeleteAsync(participant);
project.AddDomainEvent(new ParticipantRemovedEvent(request.ParticipantId, request.ProjectId));
await _employeeParticipateRepository.DeleteAsync(employeeParticipate);
project.AddDomainEvent(new ParticipantRemovedEvent(request.ParticipantId, request.ProjectId));
await _unitOfWork.SaveChangesAsync();
await _unitOfWork.SaveChangesAsync();
return Result.Success();
}
return Result.Success();
}
......
......@@ -15,19 +15,14 @@ namespace PSManagement.Application.Tracks.UseCaes.Commands.UpdateEmployeeWorkTra
{
private readonly IRepository<EmployeeTrack> _employeeTracksRepository;
private readonly ITracksRepository _tracksRepository;
private readonly IUnitOfWork _unitOfWork;
private readonly IMapper _mapper;
public UpdateEmployeeWorkTrackCommandHandler(
IUnitOfWork unitOfWork,
ITracksRepository tracksRepository,
IRepository<EmployeeTrack> employeeTracksRepository,
IMapper mapper)
IRepository<EmployeeTrack> employeeTracksRepository
)
{
_unitOfWork = unitOfWork;
_tracksRepository = tracksRepository;
_employeeTracksRepository = employeeTracksRepository;
_mapper = mapper;
}
public async Task<Result> Handle(UpdateEmployeeWorkTrackCommand request, CancellationToken cancellationToken)
......
......@@ -10,4 +10,5 @@ namespace PSManagement.Contracts.Customers.Requests
int CustomerId,
String ContactType,
String ContactValue);
}
namespace PSManagement.Contracts.Customers.Requests
{
public record RemoveContactInfoRequest(
int Id,
int CustomerId) ;
}
......@@ -2,7 +2,7 @@
namespace PSManagement.Contracts.Customers.Responses
{
public class ContactInfoRecord {
public class ContactInfoResponse {
public String ContactType { get; set; }
public String ContactValue { get; set; }
}
......
......@@ -5,8 +5,8 @@ using System.Collections.Generic;
namespace PSManagement.Contracts.Customers.Responses
{
public class CustomerRecord {
public CustomerRecord()
public class CustomerResponse {
public CustomerResponse()
{
}
......@@ -15,6 +15,6 @@ namespace PSManagement.Contracts.Customers.Responses
public String CustomerName { get; set; }
public String Email { get; set; }
public Address Address { get; set; }
public IEnumerable<ContactInfoRecord> ContactInfo { get; set; }
public IEnumerable<ContactInfoResponse> ContactInfo { get; set; }
}
}
......@@ -5,6 +5,6 @@ using System.Threading.Tasks;
namespace PSManagement.Contracts.Customers.Responses
{
public record ListCustomersResponse( IEnumerable<CustomerRecord> Customers );
public record ListCustomersResponse( IEnumerable<CustomerResponse> Customers );
}
......@@ -9,6 +9,7 @@ namespace PSManagement.Contracts.Projects.Response
public int UserId { get; set; }
public string DepartmentName { get; set; }
public PersonalInfo PersonalInfo { get; set; }
public Availability Availability { get; set; }
public WorkInfo WorkInfo { get; set; }
}
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ namespace PSManagement.Contracts.Projects.Response
public Department Executer { get; set; }
public int ProposerId { get; private set; }
public CustomerRecord Proposer { get; set; }
public CustomerResponse Proposer { get; set; }
public ICollection<StepResponse> Steps { get; set; }
public ICollection<Attachment> Attachments { get; set; }
......
using PSManagement.Domain.Customers.Entities;
using PSManagement.SharedKernel.Specification;
using System;
using System.Linq.Expressions;
namespace PSManagement.Domain.Customers.Specification
{
public class CustomerSpecification : BaseSpecification<Customer>
{
public CustomerSpecification(Expression<Func<Customer, bool>> criteria = null) : base(criteria)
{
AddInclude(e => e.ContactInfo);
}
}
}
......@@ -9,7 +9,6 @@ namespace PSManagement.Domain.Customers.ValueObjects
{
public record Address(
int StreetNumber ,
int ZipCode ,
String StreetName ,
String City );
}
......@@ -89,6 +89,7 @@ namespace PSManagement.Domain.Projects.Builders
}
public ProjectBuilder WithAttachment(Attachment[] attachments)
{
_attachments = new List<Attachment>();
foreach (Attachment attachment in attachments) {
_attachments.Add(attachment);
}
......
......@@ -20,10 +20,11 @@ namespace PSManagement.Domain.Projects.Entities
public ProposalInfo ProposalInfo { get; set; }
public ProjectInfo ProjectInfo { get; set; }
public Aggreement ProjectAggreement { get; set; }
// state management
[NotMapped]
public string CurrentState { get; private set; } // Persisted in the database
[NotMapped]
private IProjectState _state;
// information about who lead and execute the project
......@@ -94,17 +95,17 @@ namespace PSManagement.Domain.Projects.Entities
Steps = new List<Step>();
Participants = new List<Employee>();
EmployeeParticipates = new List<EmployeeParticipate>();
}
public Project()
{
_state = new ProposedState();
CurrentState = _state.StateName;
SetStateFromString(CurrentState);
}
public void SetState(IProjectState newState)
{
_state = newState;
CurrentState = _state.StateName; // Update the persisted state
CurrentState = _state.StateName;
}
public void Complete()
{
......@@ -121,9 +122,9 @@ namespace PSManagement.Domain.Projects.Entities
_state.Approve(this,projectAggreement);
}
public void Cancle()
public void Cancel(DateTime canellationTime)
{
_state.Cancle(this);
_state.Cancel(this,canellationTime);
}
public void Propose()
......
using PSManagement.Domain.Projects.ValueObjects;
using System;
namespace PSManagement.Domain.Projects.Entities
{
......@@ -11,7 +12,7 @@ namespace PSManagement.Domain.Projects.Entities
}
public void Cancle(Project project)
public void Cancel(Project project, DateTime canellationTime)
{
}
......
using PSManagement.Domain.Projects.ValueObjects;
using System;
namespace PSManagement.Domain.Projects.Entities
{
......@@ -11,7 +12,7 @@ namespace PSManagement.Domain.Projects.Entities
}
public void Cancle(Project project)
public void Cancel(Project project, DateTime canellationTime)
{
}
......
using PSManagement.Domain.Projects.ValueObjects;
using System;
namespace PSManagement.Domain.Projects.Entities
{
......@@ -7,7 +8,7 @@ namespace PSManagement.Domain.Projects.Entities
void Complete(Project project);
void Plan(Project project);
void Approve(Project project, Aggreement projectAggreement);
void Cancle(Project project);
void Cancel(Project project, DateTime canellationTime);
void Propose(Project project);
string StateName { get; }
}
......
......@@ -16,7 +16,7 @@ namespace PSManagement.Domain.Projects.Entities
project.SetState(new InProgressState());
}
public void Cancle(Project project)
public void Cancel(Project project, DateTime canellationTime)
{
project.AddDomainEvent(new ProjectCancelledEvent(project.Id,DateTime.Now));
project.SetState(new CancledState());
......
......@@ -13,9 +13,9 @@ namespace PSManagement.Domain.Projects.Entities
}
public void Cancle(Project project)
public void Cancel(Project project, DateTime canellationTime)
{
project.AddDomainEvent(new ProjectCancelledEvent(project.Id, DateTime.Now));
project.AddDomainEvent(new ProjectCancelledEvent(project.Id,canellationTime));
project.SetState(new CancledState());
}
......
using PSManagement.Domain.Projects.ValueObjects;
using System;
namespace PSManagement.Domain.Projects.Entities
{
......@@ -11,7 +12,7 @@ namespace PSManagement.Domain.Projects.Entities
}
public void Cancle(Project project)
public void Cancel(Project project, DateTime canellationTime)
{
}
......
......@@ -19,11 +19,10 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
address.Property(a => a.StreetName).HasColumnName("StreetName");
address.Property(a => a.City).HasColumnName("City");
address.Property(a => a.StreetNumber).HasColumnName("StreetNumber");
address.Property(a => a.ZipCode).HasColumnName("ZipCode");
}
);
builder.OwnsMany(c => c.ContactInfo);
builder.HasMany(c => c.ContactInfo);
}
}
......
......@@ -37,6 +37,7 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
}
);
builder.HasOne(e => e.TeamLeader)
.WithMany()
.HasForeignKey(e => e.TeamLeaderId)
......@@ -63,12 +64,17 @@ namespace PSManagement.Infrastructure.Persistence.EntitiesConfiguration
}
);
builder.Property(p => p.CurrentState).HasDefaultValue("Proposed");
builder.Property(p => p.CurrentState)
.HasDefaultValueSql("Proposed")
;
builder.HasMany(e => e.Attachments).WithOne().HasForeignKey(e => e.ProjectId);
builder.HasMany(e => e.FinancialSpending).WithOne().HasForeignKey(e=>e.ProjectId);
builder.HasMany(e => e.Tracks).WithOne(e => e.Project).HasForeignKey(e => e.ProjectId);
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace PSManagement.Infrastructure.Persistence.Migrations
{
public partial class FixCustomerEntity : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ContactInfo_Customers_CustomerId",
table: "ContactInfo");
migrationBuilder.DropPrimaryKey(
name: "PK_ContactInfo",
table: "ContactInfo");
migrationBuilder.DropColumn(
name: "ZipCode",
table: "Customers");
migrationBuilder.AlterColumn<int>(
name: "CustomerId",
table: "ContactInfo",
type: "int",
nullable: true,
oldClrType: typeof(int),
oldType: "int");
migrationBuilder.AddPrimaryKey(
name: "PK_ContactInfo",
table: "ContactInfo",
column: "Id");
migrationBuilder.CreateIndex(
name: "IX_ContactInfo_CustomerId",
table: "ContactInfo",
column: "CustomerId");
migrationBuilder.AddForeignKey(
name: "FK_ContactInfo_Customers_CustomerId",
table: "ContactInfo",
column: "CustomerId",
principalTable: "Customers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_ContactInfo_Customers_CustomerId",
table: "ContactInfo");
migrationBuilder.DropPrimaryKey(
name: "PK_ContactInfo",
table: "ContactInfo");
migrationBuilder.DropIndex(
name: "IX_ContactInfo_CustomerId",
table: "ContactInfo");
migrationBuilder.AddColumn<int>(
name: "ZipCode",
table: "Customers",
type: "int",
nullable: true);
migrationBuilder.AlterColumn<int>(
name: "CustomerId",
table: "ContactInfo",
type: "int",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AddPrimaryKey(
name: "PK_ContactInfo",
table: "ContactInfo",
columns: new[] { "CustomerId", "Id" });
migrationBuilder.AddForeignKey(
name: "FK_ContactInfo_Customers_CustomerId",
table: "ContactInfo",
column: "CustomerId",
principalTable: "Customers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}
using Microsoft.EntityFrameworkCore.Migrations;
namespace PSManagement.Infrastructure.Persistence.Migrations
{
public partial class FixProjectEntity : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "CurrentState",
table: "Projects",
type: "nvarchar(max)",
nullable: true,
defaultValueSql: "Proposed",
oldClrType: typeof(string),
oldType: "nvarchar(max)",
oldNullable: true,
oldDefaultValue: "Proposed");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "CurrentState",
table: "Projects",
type: "nvarchar(max)",
nullable: true,
defaultValue: "Proposed",
oldClrType: typeof(string),
oldType: "nvarchar(max)",
oldNullable: true,
oldDefaultValueSql: "Proposed");
}
}
}
......@@ -20,6 +20,29 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
.HasAnnotation("ProductVersion", "5.0.17")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("PSManagement.Domain.Customers.Entities.ContactInfo", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b.Property<string>("ContactType")
.HasColumnType("nvarchar(max)");
b.Property<string>("ContactValue")
.HasColumnType("nvarchar(max)");
b.Property<int?>("CustomerId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CustomerId");
b.ToTable("ContactInfo");
});
modelBuilder.Entity("PSManagement.Domain.Customers.Entities.Customer", b =>
{
b.Property<int>("Id")
......@@ -281,7 +304,7 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
b.Property<string>("CurrentState")
.ValueGeneratedOnAdd()
.HasColumnType("nvarchar(max)")
.HasDefaultValue("Proposed");
.HasDefaultValueSql("Proposed");
b.Property<int?>("CustomerId")
.HasColumnType("int");
......@@ -553,32 +576,15 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
});
});
modelBuilder.Entity("PSManagement.Domain.Customers.Entities.Customer", b =>
modelBuilder.Entity("PSManagement.Domain.Customers.Entities.ContactInfo", b =>
{
b.OwnsMany("PSManagement.Domain.Customers.Entities.ContactInfo", "ContactInfo", b1 =>
{
b1.Property<int>("CustomerId")
.HasColumnType("int");
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
b1.Property<string>("ContactType")
.HasColumnType("nvarchar(max)");
b1.Property<string>("ContactValue")
.HasColumnType("nvarchar(max)");
b1.HasKey("CustomerId", "Id");
b1.ToTable("ContactInfo");
b1.WithOwner()
.HasForeignKey("CustomerId");
});
b.HasOne("PSManagement.Domain.Customers.Entities.Customer", null)
.WithMany("ContactInfo")
.HasForeignKey("CustomerId");
});
modelBuilder.Entity("PSManagement.Domain.Customers.Entities.Customer", b =>
{
b.OwnsOne("PSManagement.Domain.Customers.ValueObjects.Address", "Address", b1 =>
{
b1.Property<int>("CustomerId")
......@@ -598,10 +604,6 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
.HasColumnType("int")
.HasColumnName("StreetNumber");
b1.Property<int>("ZipCode")
.HasColumnType("int")
.HasColumnName("ZipCode");
b1.HasKey("CustomerId");
b1.ToTable("Customers");
......@@ -611,8 +613,6 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
});
b.Navigation("Address");
b.Navigation("ContactInfo");
});
modelBuilder.Entity("PSManagement.Domain.Employees.Entities.Employee", b =>
......@@ -1181,6 +1181,8 @@ namespace PSManagement.Infrastructure.Persistence.Migrations
modelBuilder.Entity("PSManagement.Domain.Customers.Entities.Customer", b =>
{
b.Navigation("ContactInfo");
b.Navigation("Projects");
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment