Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaned all unused Using Imports References #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions Application/Behaviours/ValidationBehaviour.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using FluentValidation;
using MediatR;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using FluentValidation;
using MediatR;
using ValidationException = Application.Exceptions.ValidationException;

namespace Application.Behaviours
{
Expand All @@ -17,18 +18,21 @@ public ValidationBehavior(IEnumerable<IValidator<TRequest>> validators)
_validators = validators;
}

public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken,
RequestHandlerDelegate<TResponse> next)
{
if (_validators.Any())
{
var context = new FluentValidation.ValidationContext<TRequest>(request);
var validationResults = await Task.WhenAll(_validators.Select(v => v.ValidateAsync(context, cancellationToken)));
var context = new ValidationContext<TRequest>(request);
var validationResults =
await Task.WhenAll(_validators.Select(v => v.ValidateAsync(context, cancellationToken)));
var failures = validationResults.SelectMany(r => r.Errors).Where(f => f != null).ToList();

if (failures.Count != 0)
throw new Exceptions.ValidationException(failures);
throw new ValidationException(failures);
}

return await next();
}
}
}
}
8 changes: 2 additions & 6 deletions Application/DTOs/Account/AuthenticationRequest.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Application.DTOs.Account
namespace Application.DTOs.Account
{
public class AuthenticationRequest
{
public string Email { get; set; }
public string Password { get; set; }
}
}
}
8 changes: 3 additions & 5 deletions Application/DTOs/Account/AuthenticationResponse.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Application.DTOs.Account
Expand All @@ -12,7 +11,6 @@ public class AuthenticationResponse
public List<string> Roles { get; set; }
public bool IsVerified { get; set; }
public string JWToken { get; set; }
[JsonIgnore]
public string RefreshToken { get; set; }
[JsonIgnore] public string RefreshToken { get; set; }
}
}
}
11 changes: 3 additions & 8 deletions Application/DTOs/Account/ForgotPasswordRequest.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace Application.DTOs.Account
{
public class ForgotPasswordRequest
{
[Required]
[EmailAddress]
public string Email { get; set; }
[Required] [EmailAddress] public string Email { get; set; }
}
}
}
4 changes: 1 addition & 3 deletions Application/DTOs/Account/RefreshToken.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Application.DTOs.Account
{
Expand All @@ -17,4 +15,4 @@ public class RefreshToken
public string ReplacedByToken { get; set; }
public bool IsActive => Revoked == null && !IsExpired;
}
}
}
30 changes: 9 additions & 21 deletions Application/DTOs/Account/RegisterRequest.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace Application.DTOs.Account
{
public class RegisterRequest
{
[Required]
public string FirstName { get; set; }
[Required] public string FirstName { get; set; }

[Required]
public string LastName { get; set; }
[Required] public string LastName { get; set; }

[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
[MinLength(6)]
public string UserName { get; set; }
[Required] [EmailAddress] public string Email { get; set; }

[Required]
[MinLength(6)]
public string Password { get; set; }
[Required] [MinLength(6)] public string UserName { get; set; }

[Required]
[Compare("Password")]
public string ConfirmPassword { get; set; }
[Required] [MinLength(6)] public string Password { get; set; }

[Required] [Compare("Password")] public string ConfirmPassword { get; set; }
}
}
}
24 changes: 8 additions & 16 deletions Application/DTOs/Account/VerifyEmailRequest.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace Application.DTOs.Account
{
public class ResetPasswordRequest
{
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
public string Token { get; set; }
[Required]
[MinLength(6)]
public string Password { get; set; }
[Required] [EmailAddress] public string Email { get; set; }

[Required]
[Compare("Password")]
public string ConfirmPassword { get; set; }
[Required] public string Token { get; set; }

[Required] [MinLength(6)] public string Password { get; set; }

[Required] [Compare("Password")] public string ConfirmPassword { get; set; }
}
}
}
8 changes: 2 additions & 6 deletions Application/DTOs/Email/EmailRequest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Application.DTOs.Email
namespace Application.DTOs.Email
{
public class EmailRequest
{
Expand All @@ -11,4 +7,4 @@ public class EmailRequest
public string Body { get; set; }
public string From { get; set; }
}
}
}
8 changes: 2 additions & 6 deletions Application/Enums/Roles.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Application.Enums
namespace Application.Enums
{
public enum Roles
{
Expand All @@ -11,4 +7,4 @@ public enum Roles
Moderator,
Basic
}
}
}
14 changes: 8 additions & 6 deletions Application/Exceptions/ApiException.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace Application.Exceptions
{
public class ApiException : Exception
{
public ApiException() : base() { }
public ApiException()
{
}

public ApiException(string message) : base(message) { }
public ApiException(string message) : base(message)
{
}

public ApiException(string message, params object[] args)
: base(String.Format(CultureInfo.CurrentCulture, message, args))
: base(string.Format(CultureInfo.CurrentCulture, message, args))
{
}
}
}
}
18 changes: 7 additions & 11 deletions Application/Exceptions/ValidationException.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using FluentValidation.Results;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentValidation.Results;

namespace Application.Exceptions
{
Expand All @@ -12,15 +10,13 @@ public ValidationException() : base("One or more validation failures have occurr
{
Errors = new List<string>();
}
public List<string> Errors { get; }

public ValidationException(IEnumerable<ValidationFailure> failures)
: this()
{
foreach (var failure in failures)
{
Errors.Add(failure.ErrorMessage);
}
foreach (var failure in failures) Errors.Add(failure.ErrorMessage);
}


public List<string> Errors { get; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
using Application.Interfaces.Repositories;
using System.Threading;
using System.Threading.Tasks;
using Application.Interfaces.Repositories;
using Application.Wrappers;
using AutoMapper;
using Domain.Entities;
using MediatR;
using System.Threading;
using System.Threading.Tasks;

namespace Application.Features.Products.Commands.CreateProduct
{
public partial class CreateProductCommand : IRequest<Response<int>>
public class CreateProductCommand : IRequest<Response<int>>
{
public string Name { get; set; }
public string Barcode { get; set; }
public string Description { get; set; }
public decimal Rate { get; set; }
}

public class CreateProductCommandHandler : IRequestHandler<CreateProductCommand, Response<int>>
{
private readonly IProductRepositoryAsync _productRepository;
private readonly IMapper _mapper;
private readonly IProductRepositoryAsync _productRepository;

public CreateProductCommandHandler(IProductRepositoryAsync productRepository, IMapper mapper)
{
_productRepository = productRepository;
Expand All @@ -32,4 +34,4 @@ public async Task<Response<int>> Handle(CreateProductCommand request, Cancellati
return new Response<int>(product.Id);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
using Application.Interfaces.Repositories;
using Domain.Entities;
using FluentValidation;
using Microsoft.EntityFrameworkCore.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading;
using System.Threading.Tasks;
using Application.Interfaces.Repositories;
using FluentValidation;

namespace Application.Features.Products.Commands.CreateProduct
{
Expand All @@ -29,12 +23,11 @@ public CreateProductCommandValidator(IProductRepositoryAsync productRepository)
.NotEmpty().WithMessage("{PropertyName} is required.")
.NotNull()
.MaximumLength(50).WithMessage("{PropertyName} must not exceed 50 characters.");

}

private async Task<bool> IsUniqueBarcode(string barcode, CancellationToken cancellationToken)
{
return await productRepository.IsUniqueBarcodeAsync(barcode);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
using Application.Exceptions;
using System.Threading;
using System.Threading.Tasks;
using Application.Exceptions;
using Application.Interfaces.Repositories;
using Application.Wrappers;
using MediatR;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Application.Features.Products.Commands.DeleteProductById
{
public class DeleteProductByIdCommand : IRequest<Response<int>>
{
public int Id { get; set; }

public class DeleteProductByIdCommandHandler : IRequestHandler<DeleteProductByIdCommand, Response<int>>
{
private readonly IProductRepositoryAsync _productRepository;

public DeleteProductByIdCommandHandler(IProductRepositoryAsync productRepository)
{
_productRepository = productRepository;
}
public async Task<Response<int>> Handle(DeleteProductByIdCommand command, CancellationToken cancellationToken)

public async Task<Response<int>> Handle(DeleteProductByIdCommand command,
CancellationToken cancellationToken)
{
var product = await _productRepository.GetByIdAsync(command.Id);
if (product == null) throw new ApiException($"Product Not Found.");
if (product == null) throw new ApiException("Product Not Found.");
await _productRepository.DeleteAsync(product);
return new Response<int>(product.Id);
}
}
}
}
}
Loading