Skip to content
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
7 changes: 6 additions & 1 deletion BLL/BLL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

<ItemGroup>
<PackageReference Include="Bogus" Version="33.0.2" />
<PackageReference Include="FluentValidation" Version="10.1.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="10.1.0" />
<PackageReference Include="Minio" Version="3.1.13" />
<PackageReference Include="OpenIddict.Abstractions" Version="3.0.3" />
<PackageReference Include="OpenIddict.Core" Version="3.0.3" />
<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="3.0.3" />
<PackageReference Include="OpenIddict.EntityFrameworkCore.Models" Version="3.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 4 additions & 1 deletion BLL/BLLDependency.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BLL.Request;
using BLL.Helpers;
using BLL.Request;
using BLL.Services;
using FluentValidation;
using Microsoft.Extensions.Configuration;
Expand All @@ -21,6 +22,8 @@ public static void AllDependency(IServiceCollection services, IConfiguration con
services.AddTransient<ITestService, TestService>();
services.AddTransient<ICourseService, CourseService>();
services.AddTransient<ICourseStudentService, CourseStudentService>();
services.AddTransient<ITransactionService, TransactionService>();
services.AddTransient<IFileValidate, FileValidate>();

AllFluentValidationDependency(services);
}
Expand Down
38 changes: 38 additions & 0 deletions BLL/Helpers/CustomFileValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using FluentValidation.Resources;
using FluentValidation.Validators;
using Microsoft.AspNetCore.Http;

namespace BLL.Helpers
{
public class CustomFileValidator
{

}

//public class CustomFileValidator : AsyncValidatorBase
//{
// private readonly IFileValidate _fileValidate;

// public CustomFileValidator(IFileValidate fileValidate) : base("{ErrorMessage}")
// {
// _fileValidate = fileValidate;
// }

// protected override async Task<bool> IsValidAsync(PropertyValidatorContext context,
// CancellationToken cancellation)
// {
// var fileToValidate = context.PropertyValue as IFormFile;


// var (valid, errorMessage) = _fileValidate.ValidateFile(fileToValidate);

// if (valid) return true;
// context.MessageFormatter.AppendArgument("ErrorMessage", errorMessage);
// return false;

// }
//}
}
74 changes: 74 additions & 0 deletions BLL/Helpers/FileValidate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Http;

namespace BLL.Helpers
{
public interface IFileValidate
{
(bool Valid, string ErrorMessage) ValidateFile(IFormFile filetoValidate);
}

public class FileValidate : IFileValidate
{

public (bool Valid, string ErrorMessage) ValidateFile(IFormFile fileToValidate)
{
if (fileToValidate == null)
{
return (false, $"Provide Valid Image File");
}
if (!CheckIfImageFile(fileToValidate))
{
return (false, $"Provide Valid Image File");
}
return (true, $"Sample error message");

}

private bool CheckIfImageFile(IFormFile file)
{
byte[] fileBytes;
using (var ms = new MemoryStream())
{
file.CopyTo(ms);
fileBytes = ms.ToArray();
}

return GetImageFormat(fileBytes) != ImageFormat.unknown;
}

public ImageFormat GetImageFormat(byte[] bytes)
{
var bmp = Encoding.ASCII.GetBytes("BM"); // BMP
var gif = Encoding.ASCII.GetBytes("GIF"); // GIF
var png = new byte[] { 137, 80, 78, 71 }; // PNG
var tiff = new byte[] { 73, 73, 42 }; // TIFF
var tiff2 = new byte[] { 77, 77, 42 }; // TIFF
var jpeg = new byte[] { 255, 216, 255, 224 }; // jpeg
var jpeg2 = new byte[] { 255, 216, 255, 225 }; // jpeg canon



if (png.SequenceEqual(bytes.Take(png.Length)))
return ImageFormat.png;

if (jpeg.SequenceEqual(bytes.Take(jpeg.Length)))
return ImageFormat.jpeg;

if (jpeg2.SequenceEqual(bytes.Take(jpeg2.Length)))
return ImageFormat.jpeg;

return ImageFormat.unknown;
}

public enum ImageFormat
{

jpeg,
png,
unknown
}
}
}
9 changes: 9 additions & 0 deletions BLL/Request/CustomerMarker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Security.Claims;

namespace BLL.Request
{
public class RequestMaker
{
public ClaimsPrincipal Principal { get; set; }
}
}
146 changes: 144 additions & 2 deletions BLL/Services/TestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using DLL.DBContext;
using DLL.Models;
using DLL.Repositories;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
Expand All @@ -16,18 +17,32 @@ public interface ITestService
Task InsertData();
Task DummyData1();
Task DummyData2();
Task AddNewRoles();
Task AddNewUser();
//Task CreateAndroidAndWebClient();
}

public class TestService : ITestService
{
private readonly IUnitOfWork _unitOfWork;
private readonly ApplicationDbContext _context;
private readonly RoleManager<ApplicationRole> _roleManager;
private readonly UserManager<ApplicationUser> _userManager;
//private readonly IOpenIddictApplicationManager _openIddictApplicationManager;


public TestService(IUnitOfWork unitOfWork, ApplicationDbContext context)
public TestService(IUnitOfWork unitOfWork,
ApplicationDbContext context, RoleManager<ApplicationRole> roleManager,
UserManager<ApplicationUser> userManager
//IOpenIddictApplicationManager openIddictApplicationManager
)
{
_unitOfWork = unitOfWork;
_context = context;
_roleManager = roleManager;
_userManager = userManager;
//_openIddictApplicationManager = openIddictApplicationManager;
//_openIddictApplicationManager = openIddictApplicationManager;
}

public async Task InsertData()
Expand Down Expand Up @@ -68,7 +83,6 @@ public async Task DummyData1()

public async Task DummyData2()
{

// var courseDummy = new Faker<Course>()
// .RuleFor(o => o.Name, f => f.Name.FirstName())
// .RuleFor(o => o.Code, f => f.Name.LastName())
Expand Down Expand Up @@ -99,5 +113,133 @@ public async Task DummyData2()
count += 5;
}
}

public async Task AddNewRoles()
{
var roleList = new List<string>()
{
"admin",
"manager",
"supervisor"
};

foreach (var role in roleList)
{
var exits = await _roleManager.FindByNameAsync(role);

if (exits == null)
{
await _roleManager.CreateAsync(new ApplicationRole()
{
Name = role
});
}
}
}

public async Task AddNewUser()
{
var userList = new List<ApplicationUser>()
{
new ApplicationUser()
{
UserName = "tapos.aa@gmail.com",
Email = "tapos.aa@gmail.com",
FullName = "biswa nath ghosh tapos"
},
new ApplicationUser()
{
UserName = "sanjib@gmail.com",
Email = "sanjib@gmail.com",
FullName = "sanjib dhar"
},
new ApplicationUser()
{
UserName = "monir@gmail.com",
Email = "monir@gmail.com",
FullName = "monir hossain"
},
};

foreach (var user in userList)
{
var userExits = await _userManager.FindByEmailAsync(user.Email);

if (userExits == null)
{
var insertedData = await _userManager.CreateAsync(user, "abc123$..A!");

if (insertedData.Succeeded)
{
var myRole = "";
if (user.Email == "tapos.aa@gmail.com")
{
myRole = "admin";
}
else if (user.Email == "sanjib@gmail.com")
{
myRole = "manager";
}
else if (user.Email == "monir@gmail.com")
{
myRole = "supervisor";
}

await _userManager.AddToRoleAsync(user, myRole);
}
}
}
}

//public async Task CreateAndroidAndWebClient()
//{
// var listOfClient = new List<OpenIddictApplicationDescriptor>()
// {
// new OpenIddictApplicationDescriptor()
// {
// ClientId = "udemy_android_application",
// ClientSecret = "udemy123",
// DisplayName = "our android client",
// Permissions =
// {
// OpenIddictConstants.Permissions.Endpoints.Authorization,
// OpenIddictConstants.Permissions.Endpoints.Logout,
// OpenIddictConstants.Permissions.Endpoints.Token,
// OpenIddictConstants.Permissions.GrantTypes.Password,
// OpenIddictConstants.Permissions.GrantTypes.RefreshToken,
// OpenIddictConstants.Permissions.Scopes.Email,
// OpenIddictConstants.Permissions.Scopes.Profile,
// OpenIddictConstants.Permissions.Scopes.Roles,
// }
// },
// new OpenIddictApplicationDescriptor()
// {
// ClientId = "udemy_web_application",
// ClientSecret = "udemy456",
// DisplayName = "our web application client",
// Permissions =
// {
// OpenIddictConstants.Permissions.Endpoints.Authorization,
// OpenIddictConstants.Permissions.Endpoints.Logout,
// OpenIddictConstants.Permissions.Endpoints.Token,
// OpenIddictConstants.Permissions.GrantTypes.Password,
// OpenIddictConstants.Permissions.GrantTypes.RefreshToken,
// OpenIddictConstants.Permissions.Scopes.Email,
// OpenIddictConstants.Permissions.Scopes.Profile,
// OpenIddictConstants.Permissions.Scopes.Roles,
// }
// }
// };

// foreach (var application in listOfClient)
// {
// var applicationExists = await _openIddictApplicationManager.FindByClientIdAsync(application.ClientId);

// if (applicationExists == null)
// {
// await _openIddictApplicationManager.CreateAsync(application);
// }
// }
//}
}
}
56 changes: 56 additions & 0 deletions BLL/Services/TransactionService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using DLL.Models;
using DLL.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL.Services
{
public interface ITransactionService
{
Task FinancialTransaction();
}

public class TransactionService : ITransactionService
{
private readonly IUnitOfWork _unitOfWork;

public TransactionService(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}

public async Task FinancialTransaction()
{
//var rand = new Random();
//var amount = rand.Next(1000);
//var transaction = new TransactionHistory()
//{
// Amount = amount
//};
//var CustomerBalance = await _unitOfWork.CustomerBalanceRepository
// .FindAsync(x => x.Email == "ghabiassaad@gmail.com");
//CustomerBalance.Balance += amount;
//await _unitOfWork.TransactionHistoryRepository.CreateAsync(transaction);
//_unitOfWork.CustomerBalanceRepository.Update(CustomerBalance);
//await _unitOfWork.SaveAsync();


var rand = new Random();
var amount = rand.Next(1000);
var transaction = new TransactionHistory()
{
Amount = amount
};
await _unitOfWork.TransactionHistoryRepository.CreateAsync(transaction);
if (await _unitOfWork.SaveAsync())
{
await _unitOfWork.CustomerBalanceRepository.MustUpdateBalanceAsync("ghabiassaad@gmail.com", amount);
};


}
}
}
Loading