Compare commits
5 Commits
c5273f467e
...
2ce0890f12
| Author | SHA1 | Date |
|---|---|---|
|
|
2ce0890f12 | |
|
|
fbeb685aea | |
|
|
9c2b6bfb44 | |
|
|
e752965d6f | |
|
|
3de771f1a9 |
|
|
@ -5,7 +5,7 @@ using TIAM.Database.DbContexts;
|
||||||
namespace TIAM.Database.Test
|
namespace TIAM.Database.Test
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class DatabaseTest : DatabaseTestModelBase
|
public class DatabaseTest //: DatabaseTestModelBase<TiamDbContextBase>
|
||||||
{
|
{
|
||||||
|
|
||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
using AyCode.Database.Tests;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AyCode.Database.DataLayers.Users;
|
||||||
|
using TIAM.Database.DataLayers.ServiceProviders;
|
||||||
|
using TIAM.Database.DataLayers.Users;
|
||||||
|
using TIAM.Database.DbContexts;
|
||||||
|
|
||||||
|
namespace TIAM.Database.Test
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class ServiceProviderDalTest : DatabaseTestModelBase<ServiceProviderDbContext>
|
||||||
|
{
|
||||||
|
private ServiceProviderDal _serviceProviderDal;
|
||||||
|
|
||||||
|
[TestInitialize]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_serviceProviderDal = new ServiceProviderDal();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCleanup]
|
||||||
|
public void TearDown()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
//[DataRow(Guid.Parse("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
|
||||||
|
public async Task GetPermissionContextMappingByContext_ReturnsPermissionContextMapping_WhenPermissionContextMappingExists()//(Guid contextId)
|
||||||
|
{
|
||||||
|
var contextId = Guid.Parse("540271F6-C604-4C16-8160-D5A7CAFEDF00");
|
||||||
|
|
||||||
|
var permMapping = await _serviceProviderDal.GetPermissionContextMappingByContextIdAsync(contextId);
|
||||||
|
|
||||||
|
Assert.IsNotNull(permMapping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using AyCode.Database.Tests;
|
using AyCode.Database.DataLayers;
|
||||||
|
using AyCode.Database.Tests;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
|
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
|
@ -10,7 +11,7 @@ using TIAM.Entities.Users;
|
||||||
namespace TIAM.Database.Test
|
namespace TIAM.Database.Test
|
||||||
{
|
{
|
||||||
[TestClass]
|
[TestClass]
|
||||||
public class UserDalTests : DatabaseTestModelBase
|
public class UserDalTests : DatabaseTestModelBase<UserDbContext>
|
||||||
{
|
{
|
||||||
private Mock<UserDbContext> _mockContext;
|
private Mock<UserDbContext> _mockContext;
|
||||||
private UserDal _userDal;
|
private UserDal _userDal;
|
||||||
|
|
@ -18,109 +19,143 @@ namespace TIAM.Database.Test
|
||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void TestInitialize()
|
public void TestInitialize()
|
||||||
{
|
{
|
||||||
var options = new DbContextOptionsBuilder<UserDbContext>()
|
//var options = new DbContextOptionsBuilder<UserDbContext>()
|
||||||
.UseInMemoryDatabase(databaseName: "UserDatabase")
|
// .UseInMemoryDatabase(databaseName: "UserDatabase")
|
||||||
.Options;
|
// .Options;
|
||||||
|
|
||||||
_mockContext = new Mock<UserDbContext>(options);
|
//_mockContext = new Mock<UserDbContext>(options);
|
||||||
|
|
||||||
var mockSet = new Mock<DbSet<User>>();
|
//var mockSet = new Mock<DbSet<User>>();
|
||||||
_mockContext.Setup(c => c.Users).Returns(mockSet.Object);
|
//_mockContext.Setup(c => c.Users).Returns(mockSet.Object);
|
||||||
|
|
||||||
_userDal = new UserDal(_mockContext.Object);
|
//_userDal = new UserDal(_mockContext.Object);
|
||||||
|
|
||||||
|
_userDal = PooledDal.CreateDal<UserDal>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
[DataRow("test@tiam.hu")]
|
||||||
|
public void GetUserByEmail_ReturnsUser_WhenUserExists(string email)
|
||||||
|
{
|
||||||
|
//var userDal = PooledDal.CreateDal<UserDal>();
|
||||||
|
var user = _userDal.GetUserByEmail(email);
|
||||||
|
|
||||||
|
Assert.IsNotNull(user);
|
||||||
|
Assert.AreEqual(email, user.EmailAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
[DataRow("test@tiam.hu")]
|
[DataRow("test@tiam.hu")]
|
||||||
public async Task GetUserByEmailAsync_ReturnsUser_WhenUserExists(string email)
|
public async Task GetUserByEmailAsync_ReturnsUser_WhenUserExists(string email)
|
||||||
{
|
{
|
||||||
// Arrange
|
User? user = null;
|
||||||
var user = new User { Email = email };
|
//var userDal = PooledDal.CreateDal<UserDal>();
|
||||||
var users = new[] { user }.AsQueryable();
|
|
||||||
|
|
||||||
var mockSet = new Mock<DbSet<User>>();
|
user = await _userDal.GetUserByEmailAsync(email).ConfigureAwait(false);
|
||||||
mockSet.As<IQueryable<User>>().Setup(m => m.Provider).Returns(users.Provider);
|
|
||||||
mockSet.As<IQueryable<User>>().Setup(m => m.Expression).Returns(users.Expression);
|
|
||||||
mockSet.As<IQueryable<User>>().Setup(m => m.ElementType).Returns(users.ElementType);
|
|
||||||
mockSet.As<IQueryable<User>>().Setup(m => m.GetEnumerator()).Returns(users.GetEnumerator());
|
|
||||||
|
|
||||||
_mockContext.Setup(c => c.Users).Returns(mockSet.Object);
|
//user = await _userDal.SessionAsync(ctx => ctx.Users.FirstOrDefault(x => x.EmailAddress == email)).ConfigureAwait(false);
|
||||||
|
|
||||||
// Act
|
//await using (var ctx = _userDal.Context)
|
||||||
var result = await _userDal.GetUserByEmailAsync(email);
|
//{
|
||||||
|
// user = await ctx.Users.FirstOrDefaultAsync(x => x.EmailAddress == email).ConfigureAwait(false);
|
||||||
|
//}
|
||||||
|
|
||||||
// Assert
|
|
||||||
Assert.IsNotNull(result);
|
Assert.IsNotNull(user);
|
||||||
Assert.AreEqual(email, result.Email);
|
Assert.AreEqual(email, user.EmailAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
//[TestMethod]
|
||||||
[DataRow("test@test.hu")]
|
//[DataRow("test@tiam.hu")]
|
||||||
public async Task GetUserByEmailAsync_ReturnsNull_WhenUserDoesNotExist(string email)
|
//public async Task GetUserByEmailAsync_ReturnsUser_WhenUserExists(string email)
|
||||||
{
|
//{
|
||||||
// Arrange
|
// // Arrange
|
||||||
var users = new User[0].AsQueryable();
|
// var user = new User { EmailAddress = email };
|
||||||
|
// var users = new[] { user }.AsQueryable();
|
||||||
|
|
||||||
var mockSet = new Mock<DbSet<User>>();
|
// var mockSet = new Mock<DbSet<User>>();
|
||||||
mockSet.As<IQueryable<User>>().Setup(m => m.Provider).Returns(users.Provider);
|
// mockSet.As<IQueryable<User>>().Setup(m => m.Provider).Returns(users.Provider);
|
||||||
mockSet.As<IQueryable<User>>().Setup(m => m.Expression).Returns(users.Expression);
|
// mockSet.As<IQueryable<User>>().Setup(m => m.Expression).Returns(users.Expression);
|
||||||
mockSet.As<IQueryable<User>>().Setup(m => m.ElementType).Returns(users.ElementType);
|
// mockSet.As<IQueryable<User>>().Setup(m => m.ElementType).Returns(users.ElementType);
|
||||||
mockSet.As<IQueryable<User>>().Setup(m => m.GetEnumerator()).Returns(users.GetEnumerator());
|
// mockSet.As<IQueryable<User>>().Setup(m => m.GetEnumerator()).Returns(users.GetEnumerator());
|
||||||
|
|
||||||
_mockContext.Setup(c => c.Users).Returns(mockSet.Object);
|
// _mockContext.Setup(c => c.Users).Returns(mockSet.Object);
|
||||||
|
|
||||||
// Act
|
// // Act
|
||||||
var result = await _userDal.GetUserByEmailAsync(email);
|
// var result = await _userDal.GetUserByEmailAsync(email);
|
||||||
|
|
||||||
// Assert
|
// // Assert
|
||||||
Assert.IsNull(result);
|
// Assert.IsNotNull(result);
|
||||||
}
|
// Assert.AreEqual(email, result.EmailAddress);
|
||||||
|
//}
|
||||||
|
|
||||||
[TestMethod]
|
//[TestMethod]
|
||||||
[DataRow("test@test.com", "+1234567890", "password")]
|
//[DataRow("TEST@TEST.COM")]
|
||||||
public async Task CreateUserAsync_ShouldReturnTrue_WhenUserIsCreated(string email, string phoneNumbr, string password)
|
//public async Task GetUserByEmailAsync_ReturnsNull_WhenUserDoesNotExist(string email)
|
||||||
{
|
//{
|
||||||
// Arrange
|
// // Arrange
|
||||||
var user = new User
|
// var users = new User[0].AsQueryable();
|
||||||
{
|
|
||||||
Id = Guid.NewGuid(),
|
|
||||||
Email = email,
|
|
||||||
PhoneNumber = phoneNumbr,
|
|
||||||
Password = password
|
|
||||||
};
|
|
||||||
|
|
||||||
var mockSet = new Mock<DbSet<User>>();
|
// var mockSet = new Mock<DbSet<User>>();
|
||||||
_mockContext.Setup(x => x.Users).Returns(mockSet.Object);
|
// mockSet.As<IQueryable<User>>().Setup(m => m.Provider).Returns(users.Provider);
|
||||||
_mockContext.Setup(x => x.Users.Add(user)).Returns(() => null);
|
// mockSet.As<IQueryable<User>>().Setup(m => m.Expression).Returns(users.Expression);
|
||||||
|
// mockSet.As<IQueryable<User>>().Setup(m => m.ElementType).Returns(users.ElementType);
|
||||||
|
// mockSet.As<IQueryable<User>>().Setup(m => m.GetEnumerator()).Returns(users.GetEnumerator());
|
||||||
|
|
||||||
_mockContext.Setup(x => x.SaveChangesAsync(It.IsAny<CancellationToken>()))
|
// _mockContext.Setup(c => c.Users).Returns(mockSet.Object);
|
||||||
.ReturnsAsync(1)
|
|
||||||
.Verifiable();
|
|
||||||
|
|
||||||
// Act
|
// // Act
|
||||||
var result = await _userDal.CreateUserAsync(user);
|
// var result = await _userDal.GetUserByEmailAsync(email);
|
||||||
|
|
||||||
// Assert
|
// // Assert
|
||||||
Assert.IsTrue(result);
|
// Assert.IsNull(result);
|
||||||
}
|
//}
|
||||||
|
|
||||||
[TestMethod]
|
//[TestMethod]
|
||||||
[DataRow("test@test.com", "+1234567890", "password")]
|
//[DataRow("TEST@TEST.COM", "+1234567890", "password")]
|
||||||
public async Task UpdateUserAsync_ShouldUpdateUser(string email, string phoneNumbr, string password)
|
//public async Task CreateUserAsync_ShouldReturnTrue_WhenUserIsCreated(string email, string phoneNumbr, string password)
|
||||||
{
|
//{
|
||||||
// Arrange
|
// // Arrange
|
||||||
var user = new User(Guid.NewGuid(), email, phoneNumbr, password);
|
// var user = new User
|
||||||
_mockContext.Object.Users.Add(user);
|
// {
|
||||||
await _mockContext.Object.SaveChangesAsync();
|
// Id = Guid.NewGuid(),
|
||||||
|
// EmailAddress = email,
|
||||||
|
// PhoneNumber = phoneNumbr,
|
||||||
|
// Password = password
|
||||||
|
// };
|
||||||
|
|
||||||
// Act
|
// var mockSet = new Mock<DbSet<User>>();
|
||||||
user.Email = email;
|
// _mockContext.Setup(x => x.Users).Returns(mockSet.Object);
|
||||||
var result = await _userDal.UpdateUserAsync(user);
|
// _mockContext.Setup(x => x.Users.Add(user)).Returns(() => null);
|
||||||
|
|
||||||
// Assert
|
// _mockContext.Setup(x => x.SaveChangesAsync(It.IsAny<CancellationToken>()))
|
||||||
Assert.IsTrue(result);
|
// .ReturnsAsync(1)
|
||||||
var updatedUser = _mockContext.Object.Users.Single(u => u.Email == user.Email);
|
// .Verifiable();
|
||||||
Assert.AreEqual(email, updatedUser.Email);
|
|
||||||
}
|
// // Act
|
||||||
|
// var result = await _userDal.CreateUserAsync(user);
|
||||||
|
|
||||||
|
// // Assert
|
||||||
|
// Assert.IsTrue(result);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//[TestMethod]
|
||||||
|
//[DataRow("TEST@TEST.COM", "+1234567890", "password")]
|
||||||
|
//public async Task UpdateUserAsync_ShouldUpdateUser(string email, string phoneNumbr, string password)
|
||||||
|
//{
|
||||||
|
// // Arrange
|
||||||
|
// var user = new User(Guid.NewGuid(), email, phoneNumbr, password);
|
||||||
|
// _mockContext.Object.Users.Add(user);
|
||||||
|
// await _mockContext.Object.SaveChangesAsync();
|
||||||
|
|
||||||
|
// // Act
|
||||||
|
// user.EmailAddress = email;
|
||||||
|
// var result = await _userDal.UpdateUserAsync(user);
|
||||||
|
|
||||||
|
// // Assert
|
||||||
|
// Assert.IsTrue(result);
|
||||||
|
// var updatedUser = _mockContext.Object.Users.Single(u => u.EmailAddress == user.EmailAddress);
|
||||||
|
// Assert.AreEqual(email, updatedUser.EmailAddress);
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -18,34 +18,34 @@ namespace TIAM.Database.DataLayers.Users
|
||||||
|
|
||||||
public Task<List<User>> GetUsersAsync()
|
public Task<List<User>> GetUsersAsync()
|
||||||
{
|
{
|
||||||
return Ctx.Users.ToListAsync();
|
return Context.Users.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<User?> GetUserByEmailAsync(string email)
|
public Task<User?> GetUserByEmailAsync(string email)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Getting user from db {email}");
|
Console.WriteLine($"Getting user from db {email}");
|
||||||
var emailLower = email.ToLower();
|
var emailLower = email.ToLower();
|
||||||
return Ctx.Users.SingleOrDefaultAsync(x=>x.Email.ToLower() == emailLower);
|
return Context.Users.SingleOrDefaultAsync(x=>x.EmailAddress.ToLower() == emailLower);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> CreateUserAsync(User user)
|
public Task<bool> CreateUserAsync(User user)
|
||||||
{
|
{
|
||||||
user.Created = DateTime.UtcNow;
|
user.Created = DateTime.UtcNow;
|
||||||
user.Modified = DateTime.UtcNow;
|
user.Modified = DateTime.UtcNow;
|
||||||
Ctx.Users.Add(user);
|
Context.Users.Add(user);
|
||||||
Console.WriteLine($"Saving user to db {user.Id}, {user.Email}, {user.PhoneNumber}, {user.Password}");
|
Console.WriteLine($"Saving user to db {user.Id}, {user.EmailAddress}, {user.PhoneNumber}, {user.Password}");
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x=>x.Result > 0);
|
return Context.SaveChangesAsync().ContinueWith(x=>x.Result > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> UpdateUserAsync(User user)
|
public Task<bool> UpdateUserAsync(User user)
|
||||||
{
|
{
|
||||||
var existingUser = Ctx.Users.FirstOrDefault(u => u.Email == user.Email);
|
var existingUser = Context.Users.FirstOrDefault(u => u.EmailAddress == user.EmailAddress);
|
||||||
if (existingUser != null)
|
if (existingUser != null)
|
||||||
{
|
{
|
||||||
//user.Modified = DateTime.UtcNow; //ezt nem kell megadni, a háttérben ezt magától megcsinálja a DbContextBase - J.
|
//user.Modified = DateTime.UtcNow; //ezt nem kell megadni, a háttérben ezt magától megcsinálja a DbContextBase - J.
|
||||||
existingUser = user;
|
existingUser = user;
|
||||||
Ctx.Users.Update(existingUser);
|
Context.Users.Update(existingUser);
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18,37 +18,37 @@ namespace TIAM.Database.DataLayers.Users
|
||||||
|
|
||||||
public Task<List<AuctionBid>> GetBids()
|
public Task<List<AuctionBid>> GetBids()
|
||||||
{
|
{
|
||||||
return Ctx.AuctionBids.ToListAsync();
|
return Context.AuctionBids.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<List<AuctionBid>> GetBidsByEmail(string email)
|
public Task<List<AuctionBid>> GetBidsByEmail(string email)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Getting bid from db {email}");
|
Console.WriteLine($"Getting bid from db {email}");
|
||||||
var emailLower = email.ToLower();
|
var emailLower = email.ToLower();
|
||||||
return Ctx.AuctionBids.Where(x => x.Email.ToLower() == emailLower).ToListAsync();
|
return Context.AuctionBids.Where(x => x.Email.ToLower() == emailLower).ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<AuctionBid?> GetBidById(Guid id)
|
public async Task<AuctionBid?> GetBidById(Guid id)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Getting bid from db {id}");
|
Console.WriteLine($"Getting bid from db {id}");
|
||||||
|
|
||||||
return Ctx.AuctionBids.FirstOrDefault(x => x.Id == id);
|
return Context.AuctionBids.FirstOrDefault(x => x.Id == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> CreateBidAsync(AuctionBid auctionBid)
|
public Task<bool> CreateBidAsync(AuctionBid auctionBid)
|
||||||
{
|
{
|
||||||
auctionBid.Created = DateTime.UtcNow;
|
auctionBid.Created = DateTime.UtcNow;
|
||||||
auctionBid.Modified = DateTime.UtcNow;
|
auctionBid.Modified = DateTime.UtcNow;
|
||||||
Ctx.AuctionBids.Add(auctionBid);
|
Context.AuctionBids.Add(auctionBid);
|
||||||
Console.WriteLine($"Saving user to db {auctionBid.Id}, {auctionBid.Email}, {auctionBid.PhoneNumber}");
|
Console.WriteLine($"Saving user to db {auctionBid.Id}, {auctionBid.Email}, {auctionBid.PhoneNumber}");
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> UpdateBidAsync(AuctionBid auctionBid)
|
public Task<bool> UpdateBidAsync(AuctionBid auctionBid)
|
||||||
{
|
{
|
||||||
auctionBid.Modified = DateTime.UtcNow;
|
auctionBid.Modified = DateTime.UtcNow;
|
||||||
Ctx.AuctionBids.Update(auctionBid);
|
Context.AuctionBids.Update(auctionBid);
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,29 +31,29 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
//16. (IServiceProviderDataService) get all service providers
|
//16. (IServiceProviderDataService) get all service providers
|
||||||
public Task<List<TiamServiceProvider>> GetServiceProvidersAsync()
|
public Task<List<TiamServiceProvider>> GetServiceProvidersAsync()
|
||||||
{
|
{
|
||||||
return Ctx.ServiceProviders.ToListAsync();
|
return Context.ServiceProviders.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
//18. (IServiceProviderDataService) get serviceProvider by Id
|
//18. (IServiceProviderDataService) get serviceProvider by Id
|
||||||
public virtual Task<TiamServiceProvider?> GetServiceProviderByIdAsync(Guid id)
|
public virtual Task<TiamServiceProvider?> GetServiceProviderByIdAsync(Guid id)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Getting serviceProvider from db {id}");
|
Console.WriteLine($"Getting serviceProvider from db {id}");
|
||||||
return Ctx.ServiceProviders.SingleOrDefaultAsync(x=>x.Id == id);
|
return Context.ServiceProviders.SingleOrDefaultAsync(x=>x.Id == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//15. (IServiceProviderDataService) Create service provider
|
//15. (IServiceProviderDataService) Create service provider
|
||||||
public Task<bool> CreateServiceProviderAsync(TiamServiceProvider serviceProvider)
|
public Task<bool> CreateServiceProviderAsync(TiamServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
if(serviceProvider.Name == Ctx.ServiceProviders.FirstOrDefault(x=>x.Name == serviceProvider.Name)?.Name)
|
if(serviceProvider.Name == Context.ServiceProviders.FirstOrDefault(x=>x.Name == serviceProvider.Name)?.Name)
|
||||||
{
|
{
|
||||||
throw new Exception("ServiceProvider already exists");
|
throw new Exception("ServiceProvider already exists");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
Ctx.ServiceProviders.Add(serviceProvider);
|
Context.ServiceProviders.Add(serviceProvider);
|
||||||
Console.WriteLine($"Saving serviceProvider to db {serviceProvider.Id}, {serviceProvider.Name}, {serviceProvider.OwnerId}");
|
Console.WriteLine($"Saving serviceProvider to db {serviceProvider.Id}, {serviceProvider.Name}, {serviceProvider.OwnerId}");
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x=>x.Result > 0);
|
return Context.SaveChangesAsync().ContinueWith(x=>x.Result > 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -61,12 +61,12 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
//14. (IserviceProviderDataService) Update service provider
|
//14. (IserviceProviderDataService) Update service provider
|
||||||
public Task<bool> UpdateServiceProviderAsync(TiamServiceProvider serviceProvider)
|
public Task<bool> UpdateServiceProviderAsync(TiamServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
var dbServiceProvider = Ctx.ServiceProviders.FirstOrDefault(u => u.Id == serviceProvider.Id);
|
var dbServiceProvider = Context.ServiceProviders.FirstOrDefault(u => u.Id == serviceProvider.Id);
|
||||||
if (dbServiceProvider != null)
|
if (dbServiceProvider != null)
|
||||||
{
|
{
|
||||||
dbServiceProvider = serviceProvider;
|
dbServiceProvider = serviceProvider;
|
||||||
Ctx.ServiceProviders.Update(dbServiceProvider);
|
Context.ServiceProviders.Update(dbServiceProvider);
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -77,18 +77,18 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
//13. (IserviceProviderDataService) delete service provider
|
//13. (IserviceProviderDataService) delete service provider
|
||||||
public Task<bool> DeleteServiceProviderAsync(Guid id)
|
public Task<bool> DeleteServiceProviderAsync(Guid id)
|
||||||
{
|
{
|
||||||
using (var transaction = Ctx.Database.BeginTransaction())
|
using (var transaction = Context.Database.BeginTransaction())
|
||||||
{
|
{
|
||||||
var dbServiceProvider = Ctx.ServiceProviders.FirstOrDefault(u => u.Id == id);
|
var dbServiceProvider = Context.ServiceProviders.FirstOrDefault(u => u.Id == id);
|
||||||
if (dbServiceProvider != null)
|
if (dbServiceProvider != null)
|
||||||
{
|
{
|
||||||
//get products for this provider
|
//get products for this provider
|
||||||
var products = Ctx.Products.Where(x => x.OwnerId == id).ToList();
|
var products = Context.Products.Where(x => x.OwnerId == id).ToList();
|
||||||
|
|
||||||
/*foreach (var productItem in products)
|
/*foreach (var productItem in products)
|
||||||
{
|
{
|
||||||
//delete products
|
//delete products
|
||||||
var permissionContextMappings = Ctx.PermissionContextMappings.Where(x => x.ContextId == productItem.Id).ToList();
|
var permissionContextMappings = Context.PermissionContextMappings.Where(x => x.ContextId == productItem.Id).ToList();
|
||||||
//iterate through every row
|
//iterate through every row
|
||||||
foreach (var item in permissionContextMappings)
|
foreach (var item in permissionContextMappings)
|
||||||
{
|
{
|
||||||
|
|
@ -96,20 +96,20 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
if (item.SubjectType == (int)PermissionContextMappingSubjectType.Group)
|
if (item.SubjectType == (int)PermissionContextMappingSubjectType.Group)
|
||||||
{
|
{
|
||||||
//get users in the permissiongroup
|
//get users in the permissiongroup
|
||||||
var permissionGroupUserMapping = Ctx.PermissionGroupUserMappings.Where(x => x.PermissionContextMappingId == item.Id).ToList();
|
var permissionGroupUserMapping = Context.PermissionGroupUserMappings.Where(x => x.PermissionContextMappingId == item.Id).ToList();
|
||||||
//remove every row (users) from permissiongroup
|
//remove every row (users) from permissiongroup
|
||||||
foreach (var user in permissionGroupUserMapping)
|
foreach (var user in permissionGroupUserMapping)
|
||||||
{
|
{
|
||||||
Ctx.PermissionGroupUserMappings.Remove(user);
|
Context.PermissionGroupUserMappings.Remove(user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//remove permissioncontextmappings
|
//remove permissioncontextmappings
|
||||||
Ctx.PermissionContextMappings.RemoveRange(permissionContextMappings);
|
Context.PermissionContextMappings.RemoveRange(permissionContextMappings);
|
||||||
}*/
|
}*/
|
||||||
Ctx.Products.RemoveRange(products);
|
Context.Products.RemoveRange(products);
|
||||||
Ctx.ServiceProviders.Remove(dbServiceProvider);
|
Context.ServiceProviders.Remove(dbServiceProvider);
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -135,9 +135,9 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
using (var transaction = Ctx.Database.BeginTransaction())
|
using (var transaction = Context.Database.BeginTransaction())
|
||||||
{
|
{
|
||||||
var existingPermission = Ctx.PermissionsTypes
|
var existingPermission = Context.PermissionsTypes
|
||||||
.FirstOrDefault(x => x.PermissionName == permissionsType.PermissionName)?.PermissionName;
|
.FirstOrDefault(x => x.PermissionName == permissionsType.PermissionName)?.PermissionName;
|
||||||
|
|
||||||
if (existingPermission == null)
|
if (existingPermission == null)
|
||||||
|
|
@ -145,7 +145,7 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
//get all the permissiontypes for this context
|
//get all the permissiontypes for this context
|
||||||
var permissionTypes = new List<PermissionsType>();
|
var permissionTypes = new List<PermissionsType>();
|
||||||
var nextBitValue = 0.0;
|
var nextBitValue = 0.0;
|
||||||
permissionTypes = Ctx.PermissionsTypes
|
permissionTypes = Context.PermissionsTypes
|
||||||
.Where(x => x.ContextId == permissionsType.ContextId)
|
.Where(x => x.ContextId == permissionsType.ContextId)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
|
@ -160,8 +160,8 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
nextBitValue = Math.Pow(2,0);
|
nextBitValue = Math.Pow(2,0);
|
||||||
}
|
}
|
||||||
permissionsType.PermissionBit = (int)nextBitValue;
|
permissionsType.PermissionBit = (int)nextBitValue;
|
||||||
Ctx.PermissionsTypes.Add(permissionsType);
|
Context.PermissionsTypes.Add(permissionsType);
|
||||||
Ctx.SaveChanges();
|
Context.SaveChanges();
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
@ -178,12 +178,12 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
//11. (IPermissionService) get permission types for context
|
//11. (IPermissionService) get permission types for context
|
||||||
public Task<List<PermissionsType>>? GetPermissionTypesByContextIdAsync(Guid contextId)
|
public Task<List<PermissionsType>>? GetPermissionTypesByContextIdAsync(Guid contextId)
|
||||||
{
|
{
|
||||||
return Ctx.PermissionsTypes.Where(x => x.ContextId == contextId).ToListAsync();
|
return Context.PermissionsTypes.Where(x => x.ContextId == contextId).ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<int> GetPermissionFromPermissionType(PermissionsType pType)
|
public Task<int> GetPermissionFromPermissionType(PermissionsType pType)
|
||||||
{
|
{
|
||||||
if(Ctx.PermissionsTypes.FirstOrDefault(x=>x.Id == pType.Id) != null)
|
if(Context.PermissionsTypes.FirstOrDefault(x=>x.Id == pType.Id) != null)
|
||||||
{
|
{
|
||||||
return Task.FromResult(pType.PermissionBit);
|
return Task.FromResult(pType.PermissionBit);
|
||||||
}
|
}
|
||||||
|
|
@ -197,57 +197,60 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
|
|
||||||
#region PermissionMappings
|
#region PermissionMappings
|
||||||
|
|
||||||
|
public Task<List<PermissionContextMapping>> GetPermissionContextMappingByContextIdAsync(Guid contextId)
|
||||||
|
=> SessionAsync(x => x.GetPermissionContextMappingByContextId(contextId).ToList());
|
||||||
|
|
||||||
//2. get the contexts where the user has permission
|
//2. get the contexts where the user has permission
|
||||||
public async Task<List<AssignedPermissionModel>> GetPermissionContextByUserIdAsync(Guid UserId)
|
//public async Task<List<AssignedPermissionModel>> GetPermissionModelByUserIdAsync(Guid UserId)
|
||||||
{
|
//{
|
||||||
List<AssignedPermissionModel> _permissions = new List<AssignedPermissionModel>();
|
// List<AssignedPermissionModel> _permissions = new List<AssignedPermissionModel>();
|
||||||
//get all assignedUsers
|
// //get all assignedUsers
|
||||||
List<AssignedUser> assignedUsers = await Ctx.AssignedUsers.Where(x => x.EmployeeUserId == UserId).ToListAsync();
|
// List<AssignedUser> assignedUsers = await Context.AssignedUsers.Where(x => x.EmployeeUserId == UserId).ToListAsync();
|
||||||
//List<PermissionContextMapping> _permissionContextMappings = new List<PermissionContextMapping>();
|
// //List<PermissionContextMapping> _permissionContextMappings = new List<PermissionContextMapping>();
|
||||||
List<PermissionGroupUserMapping> _permissionGroupUserMappings = new List<PermissionGroupUserMapping>();
|
// List<PermissionGroupUserMapping> _permissionGroupUserMappings = new List<PermissionGroupUserMapping>();
|
||||||
//get contexts where the user has permission
|
// //get contexts where the user has permission
|
||||||
foreach (var item in assignedUsers)
|
// foreach (var item in assignedUsers)
|
||||||
{
|
// {
|
||||||
//get the product where the permissioncontextmapping is
|
// //get the product where the permissioncontextmapping is
|
||||||
var contextMapping = await Ctx.PermissionContextMappings.FirstOrDefaultAsync(x => x.SubjectId == item.Id);
|
// var contextMapping = await Context.PermissionContextMappings.FirstOrDefaultAsync(x => x.SubjectId == item.Id);
|
||||||
if (contextMapping != null)
|
// if (contextMapping != null)
|
||||||
{
|
// {
|
||||||
_permissions.Add(new AssignedPermissionModel(item.ContextId, item.Id, (short)PermissionContextMappingSubjectType.User, item.Id.ToString(), contextMapping.Permissions));
|
// _permissions.Add(new AssignedPermissionModel(item.ContextId, item.Id, PermissionContextMappingSubjectType.User, item.Id.ToString(), contextMapping.Permissions));
|
||||||
}
|
// }
|
||||||
//get permissiongroupusermappings where the user is in the group
|
// //get permissiongroupusermappings where the user is in the group
|
||||||
_permissionGroupUserMappings = await Ctx.PermissionGroupUserMappings.Where(x => x.AssignedUserId == item.Id).ToListAsync();
|
// _permissionGroupUserMappings = await Context.PermissionGroupUserMappings.Where(x => x.AssignedUserId == item.Id).ToListAsync();
|
||||||
|
|
||||||
foreach (var groupUserMapping in _permissionGroupUserMappings)
|
// foreach (var groupUserMapping in _permissionGroupUserMappings)
|
||||||
{
|
// {
|
||||||
//get the permissioncontextmapping where the permissiongroup is
|
// //get the permissioncontextmapping where the permissiongroup is
|
||||||
var contextMapping2 = await Ctx.PermissionContextMappings.FirstOrDefaultAsync(x => x.Id == groupUserMapping.PermissionContextMappingId);
|
// var contextMapping2 = await Context.PermissionContextMappings.FirstOrDefaultAsync(x => x.Id == groupUserMapping.PermissionContextMappingId);
|
||||||
if (contextMapping2 != null)
|
// if (contextMapping2 != null)
|
||||||
{
|
// {
|
||||||
|
|
||||||
//get the group so we have the contextId
|
// //get the group so we have the contextId
|
||||||
var group = await Ctx.PermissionGroups.FirstOrDefaultAsync(x => x.Id == contextMapping2.SubjectId);
|
// var group = await Context.PermissionGroups.FirstOrDefaultAsync(x => x.Id == contextMapping2.SubjectId);
|
||||||
|
|
||||||
_permissions.Add(new AssignedPermissionModel(group.ContextId, contextMapping2.SubjectId, (short)PermissionContextMappingSubjectType.Group, group.GroupName, contextMapping2.Permissions));
|
// _permissions.Add(new AssignedPermissionModel(group.ContextId, contextMapping2.SubjectId, PermissionContextMappingSubjectType.Group, group.GroupName, contextMapping2.Permissions));
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
return _permissions;
|
// return _permissions;
|
||||||
}
|
//}
|
||||||
|
|
||||||
//3. (IPermissionService) get permissions of assigned users and groups
|
//3. (IPermissionService) get permissions of assigned users and groups
|
||||||
public Task<List<AssignedPermissionModel>> GetPermissionsOfAssignedUsersAndGroupsAsyncByContextId(Guid contextId)
|
public Task<List<AssignedPermissionModel>> GetPermissionsOfAssignedUsersAndGroupsAsyncByContextId(Guid contextId)
|
||||||
{
|
{
|
||||||
List<AssignedPermissionModel> result = new List<AssignedPermissionModel>();
|
List<AssignedPermissionModel> result = new List<AssignedPermissionModel>();
|
||||||
|
|
||||||
var AssignedUsers = Ctx.AssignedUsers.Where(x => x.ContextId == contextId).ToListAsync();
|
var AssignedUsers = Context.AssignedUsers.Where(x => x.ContextId == contextId).ToListAsync();
|
||||||
|
|
||||||
if (AssignedUsers.Result != null)
|
if (AssignedUsers.Result != null)
|
||||||
{
|
{
|
||||||
foreach (var item in AssignedUsers.Result)
|
foreach (var item in AssignedUsers.Result)
|
||||||
{
|
{
|
||||||
var mappingRow = Ctx.PermissionContextMappings.Where(x => x.SubjectId == item.Id).ToListAsync();
|
var mappingRow = Context.PermissionContextMappings.Where(x => x.SubjectId == item.Id).ToListAsync();
|
||||||
if (mappingRow.Result == null)
|
if (mappingRow.Result == null)
|
||||||
{
|
{
|
||||||
//user has no permission but is assigned... must be banned
|
//user has no permission but is assigned... must be banned
|
||||||
|
|
@ -269,13 +272,13 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var AssingedGroups = Ctx.PermissionGroups.Where(x => x.ContextId == contextId).ToListAsync();
|
var AssingedGroups = Context.PermissionGroups.Where(x => x.ContextId == contextId).ToListAsync();
|
||||||
|
|
||||||
if (AssingedGroups.Result != null)
|
if (AssingedGroups.Result != null)
|
||||||
{
|
{
|
||||||
foreach (var group in AssingedGroups.Result)
|
foreach (var group in AssingedGroups.Result)
|
||||||
{
|
{
|
||||||
var mappingRow = Ctx.PermissionContextMappings.Where(x => x.SubjectId == group.Id).ToListAsync();
|
var mappingRow = Context.PermissionContextMappings.Where(x => x.SubjectId == group.Id).ToListAsync();
|
||||||
if (mappingRow.Result == null)
|
if (mappingRow.Result == null)
|
||||||
{
|
{
|
||||||
//group has no permission but is assigned...
|
//group has no permission but is assigned...
|
||||||
|
|
@ -310,13 +313,15 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
{
|
{
|
||||||
List<PermissionContextMapping> permissionContextMappings = new List<PermissionContextMapping>();
|
List<PermissionContextMapping> permissionContextMappings = new List<PermissionContextMapping>();
|
||||||
//get all Groups where the contextId is the same
|
//get all Groups where the contextId is the same
|
||||||
var groups = Ctx.PermissionGroups.Where(x => x.ContextId == contextId).ToListAsync();
|
var groups = Context.PermissionGroups.Where(x => x.ContextId == contextId).Select(x=>x.Id).ToHashSet();
|
||||||
foreach (var item in groups.Result)
|
permissionContextMappings = Context.PermissionContextMappings.Where(x => groups.Contains(x.SubjectId)).ToList();
|
||||||
{
|
|
||||||
//get permissioncontextmapping for the group if there is, so we know what permissions the group has
|
//foreach (var item in groups.Result)
|
||||||
var pCm = Ctx.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == item.Id);
|
//{
|
||||||
permissionContextMappings.Add(pCm);
|
// //get permissioncontextmapping for the group if there is, so we know what permissions the group has
|
||||||
}
|
// var pCm = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == item.Id);
|
||||||
|
// permissionContextMappings.Add(pCm);
|
||||||
|
//}
|
||||||
return Task.FromResult(permissionContextMappings);
|
return Task.FromResult(permissionContextMappings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -324,12 +329,12 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
public Task<bool> AddUserToPermissionGroupAsync(Guid permissionGroupId, Guid userId)
|
public Task<bool> AddUserToPermissionGroupAsync(Guid permissionGroupId, Guid userId)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
using (var transaction = Ctx.Database.BeginTransaction())
|
using (var transaction = Context.Database.BeginTransaction())
|
||||||
{
|
{
|
||||||
//do we need to check if PermissionContextMappingId exists?
|
//do we need to check if PermissionContextMappingId exists?
|
||||||
var permissionGroupUserMapping = new PermissionGroupUserMapping(userId, permissionGroupId);
|
var permissionGroupUserMapping = new PermissionGroupUserMapping(userId, permissionGroupId);
|
||||||
Ctx.PermissionGroupUserMappings.Add(permissionGroupUserMapping);
|
Context.PermissionGroupUserMappings.Add(permissionGroupUserMapping);
|
||||||
Ctx.SaveChanges();
|
Context.SaveChanges();
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
@ -340,24 +345,24 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
public Task<bool> CreatePermissionGroupAsync(PermissionGroup permissionGroup, TiamServiceProvider serviceProvider)
|
public Task<bool> CreatePermissionGroupAsync(PermissionGroup permissionGroup, TiamServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
using (var transaction = Ctx.Database.BeginTransaction())
|
using (var transaction = Context.Database.BeginTransaction())
|
||||||
{
|
{
|
||||||
var existingPermissionGroup = Ctx.PermissionGroups.FirstOrDefault(x => x.GroupName == permissionGroup.GroupName)?.GroupName;
|
var existingPermissionGroup = Context.PermissionGroups.FirstOrDefault(x => x.GroupName == permissionGroup.GroupName)?.GroupName;
|
||||||
if (existingPermissionGroup == null)
|
if (existingPermissionGroup == null)
|
||||||
{
|
{
|
||||||
//create permission type 1 for the group
|
//create permission type 1 for the group
|
||||||
var permissionType = new PermissionsType(serviceProvider.Id, "View");
|
var permissionType = new PermissionsType(serviceProvider.Id, "View");
|
||||||
Ctx.PermissionsTypes.Add(permissionType);
|
Context.PermissionsTypes.Add(permissionType);
|
||||||
|
|
||||||
//Create PermissionContextMapping for the group
|
//Create PermissionContextMapping for the group
|
||||||
|
|
||||||
//create Id for the group
|
//create Id for the group
|
||||||
Guid Id = Guid.NewGuid();
|
Guid Id = Guid.NewGuid();
|
||||||
permissionGroup.Id = Id;
|
permissionGroup.Id = Id;
|
||||||
var permissionContextMapping = new PermissionContextMapping(serviceProvider.Id, Id, (short)PermissionContextMappingSubjectType.Group, 1, true);
|
var permissionContextMapping = new PermissionContextMapping(serviceProvider.Id, Id, PermissionContextMappingSubjectType.Group, 1, true);
|
||||||
Ctx.PermissionContextMappings.Add(permissionContextMapping);
|
Context.PermissionContextMappings.Add(permissionContextMapping);
|
||||||
Ctx.PermissionGroups.Add(permissionGroup);
|
Context.PermissionGroups.Add(permissionGroup);
|
||||||
Ctx.SaveChanges();
|
Context.SaveChanges();
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
|
|
@ -370,26 +375,27 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
return Task.FromResult(result);
|
return Task.FromResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<List<AssignedUser>> GetAssingedUsersInPermissionGroupByGroupId(Guid groupId)
|
public List<AssignedUser> GetAssingedUsersInPermissionGroupByGroupId(Guid groupId)
|
||||||
{
|
{
|
||||||
List<AssignedUser> assignedUsers = new List<AssignedUser>();
|
return Context.GetAssignedUsersByPermissionGroupId(groupId).ToList();
|
||||||
|
//List<AssignedUser> assignedUsers = new List<AssignedUser>();
|
||||||
|
|
||||||
//let's get the permissioncontextmapping for the group
|
////let's get the permissioncontextmapping for the group
|
||||||
var pCm = Ctx.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == groupId);
|
//var pCm = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == groupId);
|
||||||
Guid pCmId = pCm.Id;
|
//Guid pCmId = pCm.Id;
|
||||||
|
|
||||||
//let's get the permissiongroupusermappings for the permissioncontextmapping
|
////let's get the permissiongroupusermappings for the permissioncontextmapping
|
||||||
var pGum = Ctx.PermissionGroupUserMappings.Where(x => x.PermissionContextMappingId == pCmId).ToList();
|
//var pGum = Context.PermissionGroupUserMappings.Where(x => x.PermissionContextMappingId == pCmId).ToList();
|
||||||
if (pGum.Count > 0)
|
//if (pGum.Count > 0)
|
||||||
{
|
//{
|
||||||
foreach (var group in pGum)
|
// foreach (var group in pGum)
|
||||||
{
|
// {
|
||||||
assignedUsers.Add(Ctx.AssignedUsers.FirstOrDefault(x => x.Id == group.AssignedUserId));
|
// assignedUsers.Add(Context.AssignedUsers.FirstOrDefault(x => x.Id == group.AssignedUserId));
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
return Task.FromResult(assignedUsers);
|
//return Task.FromResult(assignedUsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -402,21 +408,21 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Ctx.Products.Add(product);
|
Context.Products.Add(product);
|
||||||
Console.WriteLine($"Saving product to db {product.Id}, {product.Name}, {product.OwnerId}");
|
Console.WriteLine($"Saving product to db {product.Id}, {product.Name}, {product.OwnerId}");
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//20. (IServiceProviderDataService) Update product
|
//20. (IServiceProviderDataService) Update product
|
||||||
public Task<bool> UpdateProductAsync(TiamProduct product)
|
public Task<bool> UpdateProductAsync(TiamProduct product)
|
||||||
{
|
{
|
||||||
var dbProduct = Ctx.Products.FirstOrDefault(u => u.Id == product.Id);
|
var dbProduct = Context.Products.FirstOrDefault(u => u.Id == product.Id);
|
||||||
if (dbProduct != null)
|
if (dbProduct != null)
|
||||||
{
|
{
|
||||||
dbProduct = product;
|
dbProduct = product;
|
||||||
Ctx.Products.Update(dbProduct);
|
Context.Products.Update(dbProduct);
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -425,44 +431,46 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
}
|
}
|
||||||
|
|
||||||
//21. (IServiceProviderDataService) delete product
|
//21. (IServiceProviderDataService) delete product
|
||||||
public Task<bool> DeleteProductAsync(Guid id)
|
public Task<bool> DeleteProductByIdAsync(Guid productId)
|
||||||
{
|
{
|
||||||
using (var transaction = Ctx.Database.BeginTransaction())
|
return TransactionAsync(ctx =>
|
||||||
{
|
{
|
||||||
var dbProduct = Ctx.Products.FirstOrDefault(u => u.Id == id);
|
ctx.DeleteProductById(productId);
|
||||||
if (dbProduct != null)
|
|
||||||
{
|
//var dbProduct = ctx.Products.FirstOrDefault(u => u.Id == id);
|
||||||
//get assignedUsers for this product
|
//if (dbProduct != null)
|
||||||
var assignedUsers = Ctx.AssignedUsers.Where(x => x.ContextId == id).ToList();
|
//{
|
||||||
//remove assignedUsers
|
// ctx.CleanUpAndRemoveAssignedUser();
|
||||||
foreach (var item in assignedUsers)
|
// //get assignedUsers for this product
|
||||||
{
|
// var assignedUsers = ctx.AssignedUsers.Where(x => x.ContextId == id).ToList();
|
||||||
RemoveAssignedUserByUserId(item.Id);
|
// //remove assignedUsers
|
||||||
}
|
// foreach (var item in assignedUsers)
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
// {
|
||||||
}
|
// await RemoveAssignedUserByUserIdAsync(item.Id);
|
||||||
else
|
// }
|
||||||
{
|
|
||||||
return Task.FromResult(false);
|
// return true;
|
||||||
}
|
//}
|
||||||
}
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//4. (IPermissionService) AssignPermissionToUserForContextAsync
|
//4. (IPermissionService) AssignPermissionToUserForContextAsync
|
||||||
public Task<bool> AssignPermissionToUserForContextAsync(AssignedUser assignedUser, PermissionsType permission)
|
public Task<bool> AssignPermissionToUserForContextAsync(AssignedUser assignedUser, PermissionsType permission)
|
||||||
{
|
{
|
||||||
var _assIgnedUser = Ctx.AssignedUsers.FirstOrDefault(x => x.Id == assignedUser.Id);
|
var _assIgnedUser = Context.AssignedUsers.FirstOrDefault(x => x.Id == assignedUser.Id);
|
||||||
|
|
||||||
if(_assIgnedUser != null)
|
if(_assIgnedUser != null)
|
||||||
{
|
{
|
||||||
//user exists
|
//user exists
|
||||||
var _permissionInt = GetPermissionFromPermissionType(permission);
|
var _permissionInt = GetPermissionFromPermissionType(permission);
|
||||||
|
|
||||||
var permissionContextMapping = Ctx.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == assignedUser.Id);
|
var permissionContextMapping = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == assignedUser.Id);
|
||||||
var currentPermissions = permissionContextMapping.Permissions;
|
var currentPermissions = permissionContextMapping.Permissions;
|
||||||
var newPermissions = currentPermissions + _permissionInt.Result;
|
var newPermissions = currentPermissions + _permissionInt.Result;
|
||||||
permissionContextMapping.Permissions = newPermissions;
|
permissionContextMapping.Permissions = newPermissions;
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -479,107 +487,108 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
||||||
//22. (IServiceProviderDataService) Create assignedUser
|
//22. (IServiceProviderDataService) Create assignedUser
|
||||||
public Task<AssignedUser> CreateAssignedUserAsync(AssignedUser assignedUser)
|
public Task<AssignedUser> CreateAssignedUserAsync(AssignedUser assignedUser)
|
||||||
{
|
{
|
||||||
Ctx.AssignedUsers.Add(assignedUser);
|
Context.AssignedUsers.Add(assignedUser);
|
||||||
Console.WriteLine($"Saving assignedUser to db {assignedUser.Id}, {assignedUser.ContextId}, {assignedUser.EmployeeUserId}, {assignedUser.UserRoles}");
|
Console.WriteLine($"Saving assignedUser to db {assignedUser.Id}, {assignedUser.ContextId}, {assignedUser.EmployeeUserId}, {assignedUser.UserRoles}");
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => assignedUser);
|
return Context.SaveChangesAsync().ContinueWith(x => assignedUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
//23. (IServiceProviderDataService) Get Assigned Users By ProductId
|
//23. (IServiceProviderDataService) Get Assigned Users By ProductId
|
||||||
public Task<List<AssignedUser>> GetAssignedUsersByProductIdAsync(Guid productId)
|
public Task<List<AssignedUser>> GetAssignedUsersByProductIdAsync(Guid productId)
|
||||||
{
|
{
|
||||||
return Ctx.AssignedUsers.Where(x => x.ContextId == productId).ToListAsync();
|
return Context.AssignedUsers.Where(x => x.ContextId == productId).ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//24 . (IServiceProviderDataService) Remove Assigned Users By Product Id
|
//24 . (IServiceProviderDataService) Remove Assigned Users By Product Id
|
||||||
public Task RemoveAssignedUsersByContextId(Guid contextId)
|
public Task RemoveAssignedUsersByContextId(Guid contextId)
|
||||||
{
|
{
|
||||||
using (var transaction = Ctx.Database.BeginTransaction())
|
using (var transaction = Context.Database.BeginTransaction())
|
||||||
{
|
{
|
||||||
var assignedUsers = Ctx.AssignedUsers.Where(x => x.ContextId == contextId).ToList();
|
var assignedUsers = Context.AssignedUsers.Where(x => x.ContextId == contextId).ToList();
|
||||||
//remove assignedUsers
|
//remove assignedUsers
|
||||||
|
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//25. (IServiceProviderDataService) Remove Assigned from product by AssignedUserId
|
//25. (IServiceProviderDataService) Remove Assigned from product by assignedUserId
|
||||||
public Task RemoveAssignedUser(AssignedUser assignedUser, bool removeFromGroups)
|
public Task<bool> RemoveAssignedUserAsync(AssignedUser assignedUser, bool removeFromGroups)
|
||||||
{
|
{
|
||||||
using (var transaction = Ctx.Database.BeginTransaction())
|
return TransactionAsync(ctx =>
|
||||||
{
|
{
|
||||||
var assignedUserToRemove = Ctx.AssignedUsers.FirstOrDefault(x => x.Id == assignedUser.Id);
|
var result = false;
|
||||||
//remove assignedUsers
|
var assignedUserToRemove = ctx.AssignedUsers.FirstOrDefault(x => x.Id == assignedUser.Id);
|
||||||
if (assignedUserToRemove != null)
|
|
||||||
{
|
|
||||||
if(removeFromGroups)
|
|
||||||
{
|
|
||||||
//remove permissiongroupusermappings
|
|
||||||
RemoveAssingedUserFromAllProductPermissionGroups(assignedUserToRemove.Id);
|
|
||||||
}
|
|
||||||
Ctx.AssignedUsers.Remove(assignedUserToRemove);
|
|
||||||
}
|
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task RemoveAssignedUserByUserId(Guid assignedUserId)
|
|
||||||
{
|
|
||||||
|
|
||||||
using (var transaction = Ctx.Database.BeginTransaction())
|
|
||||||
{
|
|
||||||
var assignedUser = Ctx.AssignedUsers.FirstOrDefault(x => x.Id == assignedUserId);
|
|
||||||
//remove assignedUsers
|
//remove assignedUsers
|
||||||
if (assignedUser != null)
|
if (assignedUserToRemove == null) return false;
|
||||||
|
|
||||||
|
|
||||||
|
if (removeFromGroups)
|
||||||
{
|
{
|
||||||
//CleanUp
|
|
||||||
//remove permissioncontextmappings
|
|
||||||
RemoveAssignedUserContextMappingByAssignedUserId(assignedUserId);
|
|
||||||
//remove permissiongroupusermappings
|
//remove permissiongroupusermappings
|
||||||
RemoveAssingedUserFromAllProductPermissionGroups(assignedUserId);
|
ctx.RemoveAssingedUserFromPermissionGroups(assignedUserToRemove.Id);
|
||||||
|
|
||||||
}
|
}
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
|
||||||
|
|
||||||
}
|
ctx.AssignedUsers.Remove(assignedUserToRemove);
|
||||||
|
|
||||||
|
|
||||||
|
return result;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task RemoveAssignedUserContextMappingByAssignedUserId(Guid AssignedUserId)
|
//public Task RemoveAssignedUserByUserIdAsync(Guid assignedUserId)
|
||||||
{
|
//{
|
||||||
using (var transaction = Ctx.Database.BeginTransaction())
|
// return TransactionAsync(ctx =>
|
||||||
{
|
// {
|
||||||
PermissionContextMapping? contextMapping = Ctx.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == AssignedUserId);
|
// var assignedUser = ctx.AssignedUsers.FirstOrDefault(x => x.Id == assignedUserId);
|
||||||
//remove assignedUsers
|
// //remove assignedUsers
|
||||||
if(contextMapping != null)
|
// if (assignedUser == null) return false;
|
||||||
{
|
|
||||||
Ctx.PermissionContextMappings.Remove(contextMapping);
|
|
||||||
}
|
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
|
||||||
|
|
||||||
}
|
// //CleanUp
|
||||||
}
|
// //remove permissioncontextmappings
|
||||||
|
// ctx.RemoveAssignedUserContextMappingBySubjectId(assignedUserId);
|
||||||
|
// //remove permissiongroupusermappings
|
||||||
|
// ctx.RemoveAssingedUserFromAllProductPermissionGroups(assignedUserId);
|
||||||
|
|
||||||
|
// return true;
|
||||||
|
// });
|
||||||
|
//}
|
||||||
|
|
||||||
|
//public Task RemoveAssignedUserContextMappingByAssignedUserId(Guid assignedUserId)
|
||||||
|
//{
|
||||||
|
// using (var transaction = Context.Database.BeginTransaction())
|
||||||
|
// {
|
||||||
|
// PermissionContextMapping? contextMapping = Context.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == assignedUserId);
|
||||||
|
// //remove assignedUsers
|
||||||
|
// if(contextMapping != null)
|
||||||
|
// {
|
||||||
|
// Context.PermissionContextMappings.Remove(contextMapping);
|
||||||
|
// }
|
||||||
|
// return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||||
|
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
public Task RemoveAssingedUserFromAllProductPermissionGroups(Guid assignedUserId)
|
//public Task RemoveAssingedUserFromAllProductPermissionGroups(Guid assignedUserId)
|
||||||
{
|
//{
|
||||||
using (var transaction = Ctx.Database.BeginTransaction())
|
// using (var transaction = Context.Database.BeginTransaction())
|
||||||
{
|
// {
|
||||||
var permissionGroupUserMapping = Ctx.PermissionGroupUserMappings.Where(x => x.AssignedUserId == assignedUserId);
|
// var permissionGroupUserMapping = Context.PermissionGroupUserMappings.Where(x => x.AssignedUserId == assignedUserId);
|
||||||
//remove assignedUsers
|
// //remove assignedUsers
|
||||||
|
|
||||||
if (permissionGroupUserMapping != null)
|
// if (permissionGroupUserMapping != null)
|
||||||
{
|
// {
|
||||||
foreach (var item in permissionGroupUserMapping)
|
// foreach (var item in permissionGroupUserMapping)
|
||||||
{
|
// {
|
||||||
Ctx.PermissionGroupUserMappings.Remove(item);
|
// Context.PermissionGroupUserMappings.Remove(item);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
// return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||||
|
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,109 @@
|
||||||
|
using AyCode.Database.DataLayers.Users;
|
||||||
|
using AyCode.Models.Enums;
|
||||||
|
using TIAM.Database.DbContexts;
|
||||||
|
using TIAM.Entities.Permissions;
|
||||||
|
using TIAM.Entities.Users;
|
||||||
|
|
||||||
|
namespace TIAM.Database.DataLayers.ServiceProviders;
|
||||||
|
|
||||||
|
public static class ServiceProviderDalExtension
|
||||||
|
{
|
||||||
|
public static IQueryable<AssignedUser> GetAssignedUsersByPermissionGroupId(this ServiceProviderDbContext ctx, Guid permissionGroupId)
|
||||||
|
{
|
||||||
|
return ctx.AssignedUsers
|
||||||
|
.Where(user => ctx.PermissionGroupUserMappings
|
||||||
|
.Where(x => x.PermissionGroupId == permissionGroupId)
|
||||||
|
.Select(x => x.AssignedUserId)
|
||||||
|
.Contains(user.Id));
|
||||||
|
}
|
||||||
|
|
||||||
|
//public static IQueryable<PermissionGroup> GetPermissionGroupByContextMapping(this ServiceProviderDbContext ctx, PermissionContextMapping permissionContextMapping)
|
||||||
|
//{
|
||||||
|
// if (permissionContextMapping.SubjectType == PermissionContextMappingSubjectType.Group)
|
||||||
|
// return ctx.PermissionGroups.Where(x => x.Id == permissionContextMapping.SubjectId);
|
||||||
|
// else if (permissionContextMapping.SubjectType == PermissionContextMappingSubjectType.User)
|
||||||
|
// return ctx.PermissionGroups.Where(x => x.Id == permissionContextMapping.SubjectId);
|
||||||
|
//}
|
||||||
|
|
||||||
|
public static IQueryable<PermissionContextMapping> GetPermissionContextMappingByContextId(this ServiceProviderDbContext ctx, Guid contextId)
|
||||||
|
{
|
||||||
|
var subjectIds = ctx.GetAssignedUsersByContextId(contextId).Select(x => x.Id).
|
||||||
|
Concat(ctx.PermissionGroups.Where(x => x.ContextId == contextId).Select(x => x.Id)).ToHashSet();
|
||||||
|
|
||||||
|
return ctx.GetPermissionContextMappingsBySubjectIds(subjectIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
//public static IQueryable<PermissionContextMapping> GetPermissionContextMappingByAssignedUserId(this ServiceProviderDbContext ctx, Guid assignedUserId)
|
||||||
|
//{
|
||||||
|
// var subjectIds = ctx.GetAssignedUsersByContextId(assignedUserId).Select(x => x.Id).
|
||||||
|
// Concat(ctx.PermissionGroupUserMappings.Where(x => x.AssignedUserId == assignedUserId).Select(x => x.)).ToHashSet();
|
||||||
|
|
||||||
|
// return ctx.GetPermissionContextMappingsBySubjectIds(subjectIds);
|
||||||
|
//}
|
||||||
|
|
||||||
|
public static IQueryable<PermissionContextMapping> GetPermissionContextMappingsBySubjectIds(this ServiceProviderDbContext ctx, IEnumerable<Guid> subjectIds)
|
||||||
|
=> ctx.PermissionContextMappings.Where(x => subjectIds.Contains(x.SubjectId));
|
||||||
|
|
||||||
|
public static PermissionContextMapping? GetPermissionContextMappingBySubjectId(this ServiceProviderDbContext ctx, Guid subjectId)
|
||||||
|
=> ctx.PermissionContextMappings.FirstOrDefault(x => x.SubjectId == subjectId);
|
||||||
|
|
||||||
|
public static void RemoveContextMappingBySubjectId(this ServiceProviderDbContext ctx, Guid subjectId)
|
||||||
|
{
|
||||||
|
var contextMapping = ctx.GetPermissionContextMappingBySubjectId(subjectId);
|
||||||
|
|
||||||
|
if (contextMapping == null) return;
|
||||||
|
|
||||||
|
ctx.PermissionContextMappings.Remove(contextMapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IQueryable<PermissionGroupUserMapping> GetAllPermissionGroupsByAssignedUserId(this ServiceProviderDbContext ctx, Guid assignedUserId)
|
||||||
|
=> ctx.PermissionGroupUserMappings.Where(x => x.AssignedUserId == assignedUserId);
|
||||||
|
|
||||||
|
public static void DeleteProductById(this ServiceProviderDbContext ctx, Guid productId)
|
||||||
|
{
|
||||||
|
var product = ctx.Products.FirstOrDefault(u => u.Id == productId);
|
||||||
|
if (product == null) return;
|
||||||
|
|
||||||
|
ctx.RemoveAssignedUsers(ctx.GetAssignedUsersByContextId(productId));
|
||||||
|
ctx.Products.Remove(product);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveAssingedUserFromPermissionGroups(this ServiceProviderDbContext ctx, Guid assignedUserId)
|
||||||
|
{
|
||||||
|
ctx.PermissionGroupUserMappings.RemoveRange(ctx.GetAllPermissionGroupsByAssignedUserId(assignedUserId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemoveAssignedUsers(this ServiceProviderDbContext ctx, IEnumerable<AssignedUser> assignedUsers)
|
||||||
|
{
|
||||||
|
foreach (var assignedUser in assignedUsers)
|
||||||
|
{
|
||||||
|
ctx.CleanUpAndRemoveAssignedUser(assignedUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void CleanUpAndRemoveAssignedUser(this ServiceProviderDbContext ctx, AssignedUser assignedUser)
|
||||||
|
{
|
||||||
|
ctx.RemoveContextMappingBySubjectId(assignedUser.Id);
|
||||||
|
ctx.RemoveAssingedUserFromPermissionGroups(assignedUser.Id);
|
||||||
|
|
||||||
|
ctx.AssignedUsers.Remove(assignedUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool RemoveAssignedUserById(this ServiceProviderDbContext ctx, Guid assignedUserId)
|
||||||
|
{
|
||||||
|
var assignedUser = ctx.GetAssignedUserById(assignedUserId);
|
||||||
|
|
||||||
|
if (assignedUser == null) return false;
|
||||||
|
|
||||||
|
ctx.CleanUpAndRemoveAssignedUser(assignedUser);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AssignedUser? GetAssignedUserById(this ServiceProviderDbContext ctx, Guid assignedUserId)
|
||||||
|
=> ctx.AssignedUsers.FirstOrDefault(x => x.Id == assignedUserId);
|
||||||
|
|
||||||
|
public static IQueryable<AssignedUser> GetAssignedUsersByContextId(this ServiceProviderDbContext ctx, Guid contextId)
|
||||||
|
=> ctx.AssignedUsers.Where(x => x.ContextId == contextId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AyCode.Database.DataLayers;
|
||||||
using TIAM.Database.DbContexts;
|
using TIAM.Database.DbContexts;
|
||||||
|
|
||||||
namespace TIAM.Database.DataLayers;
|
namespace TIAM.Database.DataLayers;
|
||||||
|
|
|
||||||
|
|
@ -22,21 +22,21 @@ public class TransferDestinationDal : TiamDalBase<TransferDestinationDbContext>
|
||||||
{
|
{
|
||||||
//transferDestination.Created = DateTime.UtcNow;
|
//transferDestination.Created = DateTime.UtcNow;
|
||||||
//transferDestination.Modified = DateTime.UtcNow;
|
//transferDestination.Modified = DateTime.UtcNow;
|
||||||
Ctx.TransferDestinations.Add(transferDestination);
|
Context.TransferDestinations.Add(transferDestination);
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> UpdateTransferDestinationAsync(TransferDestination transferDestination)
|
public Task<bool> UpdateTransferDestinationAsync(TransferDestination transferDestination)
|
||||||
{
|
{
|
||||||
//transferDestination.Modified = DateTime.UtcNow;
|
//transferDestination.Modified = DateTime.UtcNow;
|
||||||
Ctx.TransferDestinations.Update(transferDestination);
|
Context.TransferDestinations.Update(transferDestination);
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
return Context.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<List<TransferDestination>> GetTransferDestinations()
|
public Task<List<TransferDestination>> GetTransferDestinations()
|
||||||
{
|
{
|
||||||
|
|
||||||
return Ctx.TransferDestinations.ToListAsync();
|
return Context.TransferDestinations.ToListAsync();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,13 +3,16 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using AyCode.Database.DataLayers;
|
||||||
|
using AyCode.Database.DataLayers.Users;
|
||||||
|
using AyCode.Entities.Users;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using TIAM.Database.DbContexts;
|
using TIAM.Database.DbContexts;
|
||||||
using TIAM.Entities.Users;
|
using TIAM.Entities.Users;
|
||||||
|
|
||||||
namespace TIAM.Database.DataLayers.Users
|
namespace TIAM.Database.DataLayers.Users
|
||||||
{
|
{
|
||||||
public class UserDal : TiamDalBase<UserDbContext>
|
public class UserDal : UserDalBase<UserDbContext, User, UserTokenBase>
|
||||||
{
|
{
|
||||||
|
|
||||||
public UserDal() : base()
|
public UserDal() : base()
|
||||||
|
|
@ -22,62 +25,72 @@ namespace TIAM.Database.DataLayers.Users
|
||||||
|
|
||||||
public Task<List<User>> GetUsersAsync()
|
public Task<List<User>> GetUsersAsync()
|
||||||
{
|
{
|
||||||
return Ctx.Users.ToListAsync();
|
return Context.Users.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Task<User?> GetUserByEmailAsync(string email)
|
//public Task<User?> GetUserByEmailAsync(string email)
|
||||||
{
|
//{
|
||||||
Console.WriteLine($"Getting user from db {email}");
|
// Console.WriteLine($"Getting user from db {email}");
|
||||||
var emailLower = email.ToLower();
|
// //var emailLower = email.ToLower();
|
||||||
return Ctx.Users.SingleOrDefaultAsync(x=>x.Email.ToLower() == emailLower);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual Task<User?> GetUserByPhoneNumberAsync(string phoneNumber)
|
// return Context.GetUserByEmail(email);
|
||||||
|
// //return Context.Users.SingleOrDefaultAsync(x=>x.Email.ToLower() == emailLower);
|
||||||
|
//}
|
||||||
|
|
||||||
|
public Task<User?> GetUserByPhoneNumberAsync(string phoneNumber)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Getting user from db {phoneNumber}");
|
Console.WriteLine($"Getting user from db {phoneNumber}");
|
||||||
var phoneNumberLower = phoneNumber.ToLower();
|
var phoneNumberLower = phoneNumber.ToLower();
|
||||||
return Ctx.Users.SingleOrDefaultAsync(x=>x.PhoneNumber.ToLower() == phoneNumberLower);
|
return Context.Users.SingleOrDefaultAsync(x=>x.PhoneNumber.Equals(phoneNumberLower, StringComparison.CurrentCultureIgnoreCase));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Task<User?> GetUserByEmailOrPhoneNumberAsync(string emailOrPhoneNumber)
|
public Task<User?> GetUserByEmailOrPhoneNumberAsync(string emailOrPhoneNumber)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Getting user from db {emailOrPhoneNumber}");
|
Console.WriteLine($"Getting user from db {emailOrPhoneNumber}");
|
||||||
var emailOrPhoneNumberLower = emailOrPhoneNumber.ToLower();
|
var emailOrPhoneNumberLower = emailOrPhoneNumber.ToLower();
|
||||||
return Ctx.Users.SingleOrDefaultAsync(x=>x.Email.ToLower() == emailOrPhoneNumberLower || x.PhoneNumber.ToLower() == emailOrPhoneNumberLower);
|
return Context.Users.SingleOrDefaultAsync(x=>x.EmailAddress.Equals(emailOrPhoneNumberLower, StringComparison.CurrentCultureIgnoreCase) || x.PhoneNumber.Equals(emailOrPhoneNumberLower, StringComparison.CurrentCultureIgnoreCase));
|
||||||
}
|
}
|
||||||
|
|
||||||
//get user by Id
|
////get user by Id
|
||||||
public virtual Task<User?> GetUserByIdAsync(Guid id)
|
//public Task<User?> GetUserByIdAsync(Guid id)
|
||||||
|
//{
|
||||||
|
// Console.WriteLine($"Getting user from db {id}");
|
||||||
|
// return Context.Users.SingleOrDefaultAsync(x=>x.Id == id);
|
||||||
|
//}
|
||||||
|
|
||||||
|
public async Task<bool> CreateUserAsync(User user)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Getting user from db {id}");
|
Context.Users.Add(user);
|
||||||
return Ctx.Users.SingleOrDefaultAsync(x=>x.Id == id);
|
Console.WriteLine($"Saving user to db {user.Id}, {user.EmailAddress}, {user.PhoneNumber}, {user.Password}");
|
||||||
|
return await Context.SaveChangesAsync() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<bool> CreateUserAsync(User user)
|
|
||||||
{
|
|
||||||
user.Created = DateTime.UtcNow;
|
|
||||||
user.Modified = DateTime.UtcNow;
|
|
||||||
Ctx.Users.Add(user);
|
|
||||||
Console.WriteLine($"Saving user to db {user.Id}, {user.Email}, {user.PhoneNumber}, {user.Password}");
|
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x=>x.Result > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<bool> UpdateUserAsyncOld(User user)
|
public async Task<bool> UpdateJwtRefreshTokenAsync(string email, string refreshToken)
|
||||||
{
|
{
|
||||||
user.Modified = DateTime.UtcNow;
|
var existingUser = Context.Users.FirstOrDefault(u => u.EmailAddress == email);
|
||||||
Ctx.Users.Update(user);
|
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x=>x.Result > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<bool> UpdateUserAsync(User user)
|
|
||||||
{
|
|
||||||
var existingUser = Ctx.Users.FirstOrDefault(u => u.Email == user.Email);
|
|
||||||
if (existingUser != null)
|
if (existingUser != null)
|
||||||
{
|
{
|
||||||
//user.Modified = DateTime.UtcNow; //ezt nem kell megadni, a háttérben ezt magától megcsinálja a DbContextBase - J.
|
//user.Modified = DateTime.UtcNow; //ezt nem kell megadni, a háttérben ezt magától megcsinálja a DbContextBase - J.
|
||||||
existingUser = user;
|
existingUser.RefreshToken = refreshToken;
|
||||||
Ctx.Users.Update(existingUser);
|
|
||||||
return Ctx.SaveChangesAsync().ContinueWith(x => x.Result > 0);
|
Context.Users.Update(existingUser);
|
||||||
|
return await Context.SaveChangesAsync() > 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception("User not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> UpdateUserAsync(User user)
|
||||||
|
{
|
||||||
|
var existingUser = await Context.Users.CountAsync(u => u.EmailAddress == user.EmailAddress);
|
||||||
|
if (existingUser == 1)
|
||||||
|
{
|
||||||
|
//user.Modified = DateTime.UtcNow; //ezt nem kell megadni, a háttérben ezt magától megcsinálja a DbContextBase - J.
|
||||||
|
Context.Users.Update(user);
|
||||||
|
return await Context.SaveChangesAsync() > 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AyCode.Database.DbContexts;
|
using AyCode.Database.DbContexts;
|
||||||
|
using AyCode.Database.DbContexts.Users;
|
||||||
|
using AyCode.Entities.Users;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using TIAM.Entities.Permissions;
|
using TIAM.Entities.Permissions;
|
||||||
using TIAM.Entities.Products;
|
using TIAM.Entities.Products;
|
||||||
|
|
@ -12,8 +14,12 @@ using TIAM.Entities.Users;
|
||||||
|
|
||||||
namespace TIAM.Database.DbContexts
|
namespace TIAM.Database.DbContexts
|
||||||
{
|
{
|
||||||
public class ServiceProviderDbContext : TiamDbContextBase
|
public class ServiceProviderDbContext : TiamDbContextBase, IUserDbContextBase<User, UserTokenBase>
|
||||||
{
|
{
|
||||||
|
public DbSet<User> Users { get; set; }
|
||||||
|
public DbSet<UserTokenBase> UserTokens { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public virtual DbSet<TiamServiceProvider> ServiceProviders { get; set; }
|
public virtual DbSet<TiamServiceProvider> ServiceProviders { get; set; }
|
||||||
public virtual DbSet<TiamProduct> Products { get; set; }
|
public virtual DbSet<TiamProduct> Products { get; set; }
|
||||||
public virtual DbSet<AssignedUser> AssignedUsers { get; set; }
|
public virtual DbSet<AssignedUser> AssignedUsers { get; set; }
|
||||||
|
|
@ -45,6 +51,5 @@ namespace TIAM.Database.DbContexts
|
||||||
optionsBuilder.EnableDetailedErrors(true);
|
optionsBuilder.EnableDetailedErrors(true);
|
||||||
base.OnConfiguring(optionsBuilder);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,19 @@ using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AyCode.Database.DbContexts;
|
using AyCode.Database.DbContexts;
|
||||||
|
using AyCode.Database.DbContexts.Users;
|
||||||
|
using AyCode.Entities.Users;
|
||||||
|
using AyCode.Interfaces.Users;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using TIAM.Entities.Permissions;
|
using TIAM.Entities.Permissions;
|
||||||
using TIAM.Entities.Users;
|
using TIAM.Entities.Users;
|
||||||
|
|
||||||
namespace TIAM.Database.DbContexts
|
namespace TIAM.Database.DbContexts
|
||||||
{
|
{
|
||||||
public class UserDbContext : TiamDbContextBase
|
public class UserDbContext : TiamDbContextBase, IUserDbContextBase<User, UserTokenBase>
|
||||||
{
|
{
|
||||||
public virtual DbSet<User> Users { get; set; }
|
public virtual DbSet<User> Users { get; set; }
|
||||||
|
public DbSet<UserTokenBase> UserTokens { get; set; }
|
||||||
|
|
||||||
public UserDbContext() //: this(string.Empty)
|
public UserDbContext() //: this(string.Empty)
|
||||||
{
|
{
|
||||||
|
|
@ -37,7 +41,5 @@ namespace TIAM.Database.DbContexts
|
||||||
optionsBuilder.EnableDetailedErrors(true);
|
optionsBuilder.EnableDetailedErrors(true);
|
||||||
base.OnConfiguring(optionsBuilder);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using AyCode.Interfaces.Entities;
|
using AyCode.Interfaces.Entities;
|
||||||
using AyCode.Interfaces.TimeStampInfo;
|
using AyCode.Interfaces.TimeStampInfo;
|
||||||
|
using AyCode.Models.Enums;
|
||||||
|
|
||||||
namespace TIAM.Entities.Permissions;
|
namespace TIAM.Entities.Permissions;
|
||||||
|
|
||||||
|
|
@ -12,15 +13,15 @@ public class PermissionContextMapping : IEntityGuid, ITimeStampInfo
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public Guid SubjectId { get; set; } //group or user
|
public Guid SubjectId { get; set; } //group or user
|
||||||
|
|
||||||
public short SubjectType { get; set; } //1 for user, 2 for group
|
public PermissionContextMappingSubjectType SubjectType { get; set; } //1 for user, 2 for group
|
||||||
public int Permissions { get; set; }
|
public int Permissions { get; set; }
|
||||||
public bool IsBuiltin { get; set; }
|
public bool IsBuiltin { get; set; }
|
||||||
|
|
||||||
public DateTime Created { get; set; }
|
public DateTime Created { get; set; }
|
||||||
public DateTime Modified { get; set; }
|
public DateTime Modified { get; set; }
|
||||||
|
|
||||||
public PermissionContextMapping(Guid subjectId, short subjectType, int permissions, bool isBuiltin) : this(Guid.NewGuid(), subjectId, subjectType, permissions, isBuiltin) { }
|
public PermissionContextMapping(Guid subjectId, PermissionContextMappingSubjectType subjectType, int permissions, bool isBuiltin) : this(Guid.NewGuid(), subjectId, subjectType, permissions, isBuiltin) { }
|
||||||
public PermissionContextMapping(Guid id, Guid subjectId, short subjectType, int permissions, bool isBuiltin)
|
public PermissionContextMapping(Guid id, Guid subjectId, PermissionContextMappingSubjectType subjectType, int permissions, bool isBuiltin)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
SubjectId = subjectId;
|
SubjectId = subjectId;
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,8 @@ public class PermissionGroup : GroupBase
|
||||||
IsBuiltin = isBuiltin;
|
IsBuiltin = isBuiltin;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
|
||||||
public Guid Id { get; set; }
|
|
||||||
public Guid ContextId { get; set; }
|
public Guid ContextId { get; set; }
|
||||||
public bool IsPublic { get; set; }
|
|
||||||
public string? GroupName { get; set; }
|
public string? GroupName { get; set; }
|
||||||
public bool IsBuiltin { get; set; }
|
public bool IsBuiltin { get; set; }
|
||||||
}
|
}
|
||||||
|
|
@ -11,7 +11,7 @@ public class PermissionGroupUserMapping : IEntityGuid, ITimeStampInfo
|
||||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public Guid AssignedUserId { get; set; }
|
public Guid AssignedUserId { get; set; }
|
||||||
public Guid PermissionContextMappingId { get; set; }
|
public Guid PermissionGroupId { get; set; }
|
||||||
|
|
||||||
public DateTime Created { get; set; }
|
public DateTime Created { get; set; }
|
||||||
public DateTime Modified { get; set; }
|
public DateTime Modified { get; set; }
|
||||||
|
|
@ -19,11 +19,11 @@ public class PermissionGroupUserMapping : IEntityGuid, ITimeStampInfo
|
||||||
public PermissionGroupUserMapping(Guid assignedUserId, Guid permissionContextMappingId) : this (Guid.NewGuid(), assignedUserId, permissionContextMappingId)
|
public PermissionGroupUserMapping(Guid assignedUserId, Guid permissionContextMappingId) : this (Guid.NewGuid(), assignedUserId, permissionContextMappingId)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public PermissionGroupUserMapping(Guid id, Guid assignedUserId, Guid permissionContextMappingId)
|
public PermissionGroupUserMapping(Guid id, Guid assignedUserId, Guid permissionGroupId)
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
AssignedUserId = assignedUserId;
|
AssignedUserId = assignedUserId;
|
||||||
PermissionContextMappingId = permissionContextMappingId;
|
PermissionGroupId = permissionGroupId;
|
||||||
Created = DateTime.UtcNow;
|
Created = DateTime.UtcNow;
|
||||||
Modified = DateTime.UtcNow;
|
Modified = DateTime.UtcNow;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using AyCode.Models.Enums;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.AccessControl;
|
using System.Security.AccessControl;
|
||||||
|
|
@ -11,11 +12,11 @@ namespace TIAM.Entities.Products.DTOs
|
||||||
{
|
{
|
||||||
public Guid ContextId { get; set; }
|
public Guid ContextId { get; set; }
|
||||||
public Guid SubjectId { get; set; } //user or group id
|
public Guid SubjectId { get; set; } //user or group id
|
||||||
public short SubjectType { get; set; } //user or group
|
public PermissionContextMappingSubjectType SubjectType { get; set; } //user or group
|
||||||
public string Name { get; set; } //user email or group name
|
public string Name { get; set; } //user email or group name
|
||||||
public int PermissionsValue { get; set; }
|
public int PermissionsValue { get; set; }
|
||||||
|
|
||||||
public AssignedPermissionModel(Guid contextId, Guid subjectId, short subjectType, string name, int permissionsValue)
|
public AssignedPermissionModel(Guid contextId, Guid subjectId, PermissionContextMappingSubjectType subjectType, string name, int permissionsValue)
|
||||||
{
|
{
|
||||||
ContextId = contextId;
|
ContextId = contextId;
|
||||||
SubjectId = subjectId;
|
SubjectId = subjectId;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
using TIAMMobileApp.Services;
|
using TIAMMobileApp.Services;
|
||||||
using TIAMWebApp.Shared.Application.Interfaces;
|
using TIAMWebApp.Shared.Application.Interfaces;
|
||||||
using DevExpress.Blazor;
|
using DevExpress.Blazor;
|
||||||
using TIAMMobilApp.Services;
|
|
||||||
using System.Resources;
|
using System.Resources;
|
||||||
using AyCode.Interfaces.StorageHandlers;
|
using AyCode.Interfaces.StorageHandlers;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,28 @@
|
||||||
using AyCode.Interfaces.StorageHandlers;
|
using System.Net.Http.Json;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.JSInterop;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Net.Http.Json;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using AyCode.Interfaces.StorageHandlers;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using TIAM.Entities.Users;
|
using TIAM.Entities.Users;
|
||||||
using TIAMWebApp.Shared.Application.Interfaces;
|
using TIAMWebApp.Shared.Application.Interfaces;
|
||||||
using TIAMWebApp.Shared.Application.Models;
|
using TIAMWebApp.Shared.Application.Models;
|
||||||
using TIAMWebApp.Shared.Application.Models.ClientSide;
|
using TIAMWebApp.Shared.Application.Models.ClientSide;
|
||||||
using TIAMWebApp.Shared.Application.Models.PageModels;
|
using TIAMWebApp.Shared.Application.Models.PageModels;
|
||||||
using TIAMWebApp.Shared.Application.Utility;
|
|
||||||
|
|
||||||
namespace TIAMMobilApp.Services
|
namespace TIAMMobileApp.Services
|
||||||
{
|
{
|
||||||
public class UserDataServiceMobile : IUserDataService
|
public class UserDataServiceMobile : IUserDataService
|
||||||
{
|
{
|
||||||
private readonly HttpClient http;
|
private readonly HttpClient http;
|
||||||
private readonly ISecureStorageHandler secureStorageHandler;
|
private readonly ISecureStorageHandler secureStorageHandler;
|
||||||
|
private readonly IServiceProviderDataService _serviceProviderDataService;
|
||||||
|
|
||||||
public Dictionary<int, string> userRoleTypes { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
public Dictionary<int, string> userRoleTypes { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
||||||
|
|
||||||
public UserDataServiceMobile(HttpClient http, ISecureStorageHandler secureStorageHandler)
|
public UserDataServiceMobile(HttpClient http, ISecureStorageHandler secureStorageHandler, IServiceProviderDataService serviceProviderDataService)
|
||||||
{
|
{
|
||||||
this.http = http;
|
this.http = http;
|
||||||
this.secureStorageHandler = secureStorageHandler;
|
this.secureStorageHandler = secureStorageHandler;
|
||||||
|
_serviceProviderDataService = serviceProviderDataService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -44,25 +43,23 @@ namespace TIAMMobilApp.Services
|
||||||
|
|
||||||
public async Task<UserSessionModel> IsLoggedInAsync(Guid id)
|
public async Task<UserSessionModel> IsLoggedInAsync(Guid id)
|
||||||
{
|
{
|
||||||
UserSessionModel User = null;
|
var dbUser = await GetUserByIdAsync(id);
|
||||||
|
|
||||||
var dbUser = await GetUserByIdAsync(id);
|
|
||||||
|
|
||||||
if (dbUser != null)
|
if (dbUser != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
User = new UserSessionModel(dbUser.Id, UserType.User, dbUser.Email, 1);
|
var hasProperties = await _serviceProviderDataService.GetPropertiesByOwnerIdAsync(dbUser.Id);
|
||||||
return User;
|
var user = new UserSessionModel(dbUser.Id, UserType.User, dbUser.EmailAddress, hasProperties, 1);
|
||||||
|
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task<string> TestUserApi(int Param)
|
public async Task<string> TestUserApi(int Param)
|
||||||
{
|
{
|
||||||
var url = APIUrls.UserTest;
|
var url = APIUrls.UserTest;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
|
<IsFirstTimeProjectOpen>False</IsFirstTimeProjectOpen>
|
||||||
<ActiveDebugFramework>net7.0-windows10.0.19041.0</ActiveDebugFramework>
|
<ActiveDebugFramework>net8.0-windows10.0.19041.0</ActiveDebugFramework>
|
||||||
<ActiveDebugProfile>Windows Machine</ActiveDebugProfile>
|
<ActiveDebugProfile>Windows Machine</ActiveDebugProfile>
|
||||||
<SelectedPlatformGroup>PhysicalDevice</SelectedPlatformGroup>
|
<SelectedPlatformGroup>PhysicalDevice</SelectedPlatformGroup>
|
||||||
<DefaultDevice>pixel_5_-_api_31</DefaultDevice>
|
<DefaultDevice>pixel_5_-_api_31</DefaultDevice>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ else
|
||||||
|
|
||||||
@foreach (var dest in Users)
|
@foreach (var dest in Users)
|
||||||
{
|
{
|
||||||
<p>@dest.Email</p>
|
<p>@dest.EmailAddress</p>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ namespace TIAMWebApp.Client.Services
|
||||||
//get user's properties
|
//get user's properties
|
||||||
var hasProperties = await serviceProviderDataService.GetPropertiesByOwnerIdAsync(dbUser.Id);
|
var hasProperties = await serviceProviderDataService.GetPropertiesByOwnerIdAsync(dbUser.Id);
|
||||||
//create user session model
|
//create user session model
|
||||||
User = new UserSessionModel(dbUser.Id, UserType.User, dbUser.Email, hasProperties, 1);
|
User = new UserSessionModel(dbUser.Id, UserType.User, dbUser.EmailAddress, hasProperties, 1);
|
||||||
return User;
|
return User;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
[Route("GetTransferDestinations")]
|
[Route("GetTransferDestinations")]
|
||||||
public async Task<IEnumerable<TransferDestination>> GetTransferDestinations()
|
public async Task<IEnumerable<TransferDestination>> GetTransferDestinations()
|
||||||
{
|
{
|
||||||
return await _transferDestinationDal.Ctx.TransferDestinations.ToListAsync();
|
return await _transferDestinationDal.Context.TransferDestinations.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
|
|
@ -56,7 +56,7 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
[Route("GetTransferDestinationByCoordinates")]
|
[Route("GetTransferDestinationByCoordinates")]
|
||||||
public async Task<TransferDestination?> GetTransferDestinationByCoordinates(double latitude, double longitude)
|
public async Task<TransferDestination?> GetTransferDestinationByCoordinates(double latitude, double longitude)
|
||||||
{
|
{
|
||||||
return await _transferDestinationDal.Ctx.TransferDestinations.FirstOrDefaultAsync(x => x.Latitude == latitude && x.Longitude == longitude);
|
return await _transferDestinationDal.Context.TransferDestinations.FirstOrDefaultAsync(x => x.Latitude == latitude && x.Longitude == longitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
|
|
@ -64,7 +64,7 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
[Route("GetTransferDestinationByAddress")]
|
[Route("GetTransferDestinationByAddress")]
|
||||||
public async Task<TransferDestination?> GetTransferDestinationByAddress(string address)
|
public async Task<TransferDestination?> GetTransferDestinationByAddress(string address)
|
||||||
{
|
{
|
||||||
return await _transferDestinationDal.Ctx.TransferDestinations.FirstOrDefaultAsync(x => x.Address == address);
|
return await _transferDestinationDal.Context.TransferDestinations.FirstOrDefaultAsync(x => x.Address == address);
|
||||||
}
|
}
|
||||||
|
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
|
|
@ -102,7 +102,7 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
Console.WriteLine($"TransferDestination to be created: {Longitude}");
|
Console.WriteLine($"TransferDestination to be created: {Longitude}");
|
||||||
Console.WriteLine($"TransferDestination to be created: {Address}");
|
Console.WriteLine($"TransferDestination to be created: {Address}");
|
||||||
|
|
||||||
//await _transferDestinationDal.Ctx.TransferDestinations.AddAsync(transferDestination);
|
//await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination);
|
||||||
await _transferDestinationDal.CreateTransferDestinationAsync(transferDestination);
|
await _transferDestinationDal.CreateTransferDestinationAsync(transferDestination);
|
||||||
return Ok("yes");
|
return Ok("yes");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,8 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
private UserDal _userDal;
|
private UserDal _userDal;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||||
PasswordHasher hasher = new PasswordHasher();
|
readonly PasswordHasher _hasher = new();
|
||||||
|
|
||||||
|
|
||||||
/*private UserModel[] users = new UserModel[]
|
/*private UserModel[] users = new UserModel[]
|
||||||
{
|
{
|
||||||
|
|
@ -48,7 +48,7 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_webHostEnvironment = webHostEnvironment;
|
_webHostEnvironment = webHostEnvironment;
|
||||||
_userDal = userDal;
|
_userDal = userDal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,9 +77,9 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
{
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool isValidUser = false;
|
var isValidUser = false;
|
||||||
|
|
||||||
if (dbUser.Password == authenticateUser.Password)
|
if (dbUser.Password == authenticateUser.Password)
|
||||||
{
|
{
|
||||||
|
|
@ -91,12 +91,12 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
if (isValidUser)
|
if (isValidUser)
|
||||||
{
|
{
|
||||||
Console.WriteLine("UserModel authenticated, let's start JWT");
|
Console.WriteLine("UserModel authenticated, let's start JWT");
|
||||||
string accessToken = GenerateAccessToken(dbUser);
|
var accessToken = GenerateAccessToken(dbUser);
|
||||||
Console.WriteLine("Generate refresh token");
|
Console.WriteLine("Generate refresh token");
|
||||||
var refreshToken = GenerateRefreshToken();
|
var refreshToken = GenerateRefreshToken();
|
||||||
dbUser.RefreshToken = refreshToken;
|
dbUser.RefreshToken = refreshToken;
|
||||||
//Update userModel with refreshToken!!
|
//Update userModel with refreshToken!!
|
||||||
await _userDal.UpdateUserAsync(dbUser);
|
await _userDal.UpdateJwtRefreshTokenAsync(dbUser.EmailAddress, dbUser.RefreshToken);
|
||||||
|
|
||||||
var response = new MainResponse
|
var response = new MainResponse
|
||||||
{
|
{
|
||||||
|
|
@ -115,23 +115,23 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GenerateAccessToken(User user)
|
private string GenerateAccessToken(User user)
|
||||||
{
|
{
|
||||||
var tokenHandler = new JwtSecurityTokenHandler();
|
var tokenHandler = new JwtSecurityTokenHandler();
|
||||||
var token = new JwtSecurityToken();
|
|
||||||
Console.WriteLine("----------------------------------------------------------");
|
Console.WriteLine("----------------------------------------------------------");
|
||||||
var keyDetail = Encoding.UTF8.GetBytes(_configuration["JWT:Key"]);
|
|
||||||
|
if (_configuration["JWT:Key"] == null)
|
||||||
|
throw new SecurityTokenException("Token is null");
|
||||||
|
|
||||||
|
var keyDetail = Encoding.UTF8.GetBytes(_configuration["JWT:Key"] ?? string.Empty);
|
||||||
Console.WriteLine(_configuration["JWT:Key"]);
|
Console.WriteLine(_configuration["JWT:Key"]);
|
||||||
|
|
||||||
var claims = new List<Claim>
|
var claims = new List<Claim>
|
||||||
{
|
{
|
||||||
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
new(ClaimTypes.NameIdentifier, user.Id.ToString()),
|
||||||
new Claim(ClaimTypes.Email, user.Email)
|
new(ClaimTypes.Email, user.EmailAddress)
|
||||||
};
|
};
|
||||||
|
|
||||||
var tokenDescriptor = new SecurityTokenDescriptor
|
var tokenDescriptor = new SecurityTokenDescriptor
|
||||||
|
|
@ -142,18 +142,21 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
Subject = new ClaimsIdentity(claims),
|
Subject = new ClaimsIdentity(claims),
|
||||||
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(keyDetail), SecurityAlgorithms.HmacSha256Signature)
|
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(keyDetail), SecurityAlgorithms.HmacSha256Signature)
|
||||||
};
|
};
|
||||||
token = tokenHandler.CreateToken(tokenDescriptor) as JwtSecurityToken;
|
|
||||||
string writtenToken = tokenHandler.WriteToken(token);
|
var token = tokenHandler.CreateToken(tokenDescriptor) as JwtSecurityToken;
|
||||||
|
var writtenToken = tokenHandler.WriteToken(token);
|
||||||
Console.WriteLine(writtenToken);
|
Console.WriteLine(writtenToken);
|
||||||
|
|
||||||
return writtenToken;
|
return writtenToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("RefreshToken")]
|
[Route("RefreshToken")]
|
||||||
public async Task<IActionResult> RefreshToken(RefreshTokenRequest refreshTokenRequest)
|
public async Task<IActionResult> RefreshToken(RefreshTokenRequest? refreshTokenRequest)
|
||||||
{
|
{
|
||||||
Console.WriteLine("RefreshToken called");
|
Console.WriteLine("RefreshToken called");
|
||||||
|
|
||||||
var response = new MainResponse();
|
var response = new MainResponse();
|
||||||
if (refreshTokenRequest is null)
|
if (refreshTokenRequest is null)
|
||||||
{
|
{
|
||||||
|
|
@ -177,7 +180,7 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
{
|
{
|
||||||
//get user from db
|
//get user from db
|
||||||
dbUser = await _userDal.GetUserByEmailAsync(email.Value);
|
dbUser = await _userDal.GetUserByEmailAsync(email.Value);
|
||||||
Console.WriteLine("DbUser email: " + dbUser?.Email);
|
Console.WriteLine("DbUser email: " + dbUser?.EmailAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
//mocking - update userModel with new refreshToken so it returns true after the check below
|
//mocking - update userModel with new refreshToken so it returns true after the check below
|
||||||
|
|
@ -190,13 +193,13 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
return BadRequest(response);
|
return BadRequest(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
string newAccessToken = GenerateAccessToken(dbUser);
|
var newAccessToken = GenerateAccessToken(dbUser);
|
||||||
string refreshToken = GenerateRefreshToken();
|
var refreshToken = GenerateRefreshToken();
|
||||||
|
|
||||||
//mocking - update userModel with new refreshToken
|
//mocking - update userModel with new refreshToken
|
||||||
dbUser.RefreshToken = refreshToken;
|
dbUser.RefreshToken = refreshToken;
|
||||||
//TODO await _userManager.UpdateAsync(userModel);
|
//TODO await _userManager.UpdateAsync(userModel);
|
||||||
await _userDal.UpdateUserAsync(dbUser);
|
await _userDal.UpdateJwtRefreshTokenAsync(dbUser.EmailAddress, dbUser.RefreshToken);
|
||||||
|
|
||||||
response.IsSuccess = true;
|
response.IsSuccess = true;
|
||||||
response.Content = new AuthenticationResponse
|
response.Content = new AuthenticationResponse
|
||||||
|
|
@ -204,21 +207,22 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
RefreshToken = refreshToken,
|
RefreshToken = refreshToken,
|
||||||
AccessToken = newAccessToken
|
AccessToken = newAccessToken
|
||||||
};
|
};
|
||||||
|
|
||||||
return Ok(response);
|
return Ok(response);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("Principal is null");
|
|
||||||
return NotFound("Invalid Token Found");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Console.WriteLine("Principal is null");
|
||||||
|
return NotFound("Invalid Token Found");
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClaimsPrincipal GetPrincipalFromExpiredToken(string token)
|
private ClaimsPrincipal GetPrincipalFromExpiredToken(string token)
|
||||||
{
|
{
|
||||||
var tokenHandler = new JwtSecurityTokenHandler();
|
var tokenHandler = new JwtSecurityTokenHandler();
|
||||||
|
|
||||||
var keyDetail = Encoding.UTF8.GetBytes(_configuration["JWT:Key"]);
|
if (_configuration["JWT:Key"] == null)
|
||||||
|
throw new SecurityTokenException("Token is null");
|
||||||
|
|
||||||
|
var keyDetail = Encoding.UTF8.GetBytes(_configuration["JWT:Key"] ?? string.Empty);
|
||||||
|
|
||||||
var tokenValidationParameter = new TokenValidationParameters
|
var tokenValidationParameter = new TokenValidationParameters
|
||||||
{
|
{
|
||||||
|
|
@ -231,11 +235,11 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
IssuerSigningKey = new SymmetricSecurityKey(keyDetail),
|
IssuerSigningKey = new SymmetricSecurityKey(keyDetail),
|
||||||
};
|
};
|
||||||
|
|
||||||
SecurityToken securityToken;
|
var principal = tokenHandler.ValidateToken(token, tokenValidationParameter, out var securityToken);
|
||||||
var principal = tokenHandler.ValidateToken(token, tokenValidationParameter, out securityToken);
|
|
||||||
var jwtSecurityToken = securityToken as JwtSecurityToken;
|
if (securityToken is not JwtSecurityToken jwtSecurityToken || !jwtSecurityToken.Header.Alg.Equals(SecurityAlgorithms.HmacSha256, StringComparison.InvariantCultureIgnoreCase))
|
||||||
if (jwtSecurityToken == null || !jwtSecurityToken.Header.Alg.Equals(SecurityAlgorithms.HmacSha256, StringComparison.InvariantCultureIgnoreCase))
|
|
||||||
throw new SecurityTokenException("Invalid token");
|
throw new SecurityTokenException("Invalid token");
|
||||||
|
|
||||||
return principal;
|
return principal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -257,56 +261,54 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
public async Task<IActionResult> CreateUser([FromBody] JsonElement SerializedRegistrationModel)
|
public async Task<IActionResult> CreateUser([FromBody] JsonElement SerializedRegistrationModel)
|
||||||
{
|
{
|
||||||
Console.WriteLine("CreateUser called");
|
Console.WriteLine("CreateUser called");
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(SerializedRegistrationModel.GetRawText()))
|
if (string.IsNullOrEmpty(SerializedRegistrationModel.GetRawText()))
|
||||||
{
|
{
|
||||||
return BadRequest("SerializedLoginModel is required");
|
return BadRequest("SerializedLoginModel is required");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RegistrationModel? user = JObject.Parse(SerializedRegistrationModel.GetRawText()).ToObject<RegistrationModel>();
|
var user = JObject.Parse(SerializedRegistrationModel.GetRawText()).ToObject<RegistrationModel>();
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
if(user != null)
|
{
|
||||||
|
//add userModel to users array
|
||||||
|
//Array.Resize(ref users, users.Length + 1);
|
||||||
|
//users[users.Length - 1] = new UserModel(user.Email, user.PhoneNumber, user.Password);
|
||||||
|
|
||||||
|
|
||||||
|
var userId = Guid.NewGuid();
|
||||||
|
var email = user?.Email;
|
||||||
|
var phoneNumber = user?.PhoneNumber;
|
||||||
|
var password = user?.Password;
|
||||||
|
|
||||||
|
if (email is null || phoneNumber is null || password is null)
|
||||||
{
|
{
|
||||||
//add userModel to users array
|
return BadRequest("Invalid request");
|
||||||
//Array.Resize(ref users, users.Length + 1);
|
}
|
||||||
//users[users.Length - 1] = new UserModel(user.Email, user.PhoneNumber, user.Password);
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"User to be created: {userId}");
|
||||||
|
Console.WriteLine($"User to be created: {email}");
|
||||||
|
Console.WriteLine($"User to be created: {phoneNumber}");
|
||||||
|
Console.WriteLine($"User to be created: {password}");
|
||||||
|
|
||||||
|
await _userDal.CreateUserAsync(new User(userId, email, phoneNumber, password));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var userId = Guid.NewGuid();
|
return Ok("yes");
|
||||||
string? email = user?.Email;
|
|
||||||
string? phoneNumber = user?.PhoneNumber;
|
|
||||||
string? password = user?.Password;
|
|
||||||
|
|
||||||
if(email is null || phoneNumber is null || password is null)
|
|
||||||
{
|
|
||||||
return BadRequest("Invalid request");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine($"User to be created: {userId}");
|
|
||||||
Console.WriteLine($"User to be created: {email}");
|
|
||||||
Console.WriteLine($"User to be created: {phoneNumber}");
|
|
||||||
Console.WriteLine($"User to be created: {password}");
|
|
||||||
|
|
||||||
await _userDal.CreateUserAsync(new User(userId, email, phoneNumber, password));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Ok("yes");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("Test1")]
|
[Route("Test1")]
|
||||||
public async Task<IActionResult> TestEndpoint([FromBody] int testParam)
|
public async Task<IActionResult> TestEndpoint([FromBody] int testParam)
|
||||||
{
|
{
|
||||||
return Ok(testParam.ToString());
|
return Ok(testParam.ToString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("Test2")]
|
[Route("Test2")]
|
||||||
public string TestEndpoint2(int testParam)
|
public string TestEndpoint2(int testParam)
|
||||||
|
|
@ -345,13 +347,13 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
|
|
||||||
private bool VerifyPassword(string password, string hashedPassword)
|
private bool VerifyPassword(string password, string hashedPassword)
|
||||||
{
|
{
|
||||||
bool isPasswordValid = hasher.VerifyPassword(password, hashedPassword);
|
var isPasswordValid = _hasher.VerifyPassword(password, hashedPassword);
|
||||||
return isPasswordValid;
|
return isPasswordValid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string HashPassword(string password)
|
private string HashPassword(string password)
|
||||||
{
|
{
|
||||||
var hashedPassword = hasher.HashPassword(password);
|
var hashedPassword = _hasher.HashPassword(password);
|
||||||
return hashedPassword;
|
return hashedPassword;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,10 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine($"GetPermissionContextByUserId called with userId: {userId}");
|
Console.WriteLine($"GetPermissionContextByUserId called with userId: {userId}");
|
||||||
List<AssignedPermissionModel> response = await _serviceProviderDal.GetPermissionContextByUserIdAsync(userId);
|
//List<AssignedPermissionModel> response = await _serviceProviderDal.GetPermissionModelByUserIdAsync(userId);
|
||||||
return Ok(response);
|
//return Ok(response);
|
||||||
|
|
||||||
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,8 @@ namespace TIAMWebApp.Server.Services
|
||||||
Console.WriteLine($"Sender: {message.SenderId}");
|
Console.WriteLine($"Sender: {message.SenderId}");
|
||||||
Console.WriteLine($"Message: {message.Message}");
|
Console.WriteLine($"Message: {message.Message}");
|
||||||
//resolve user!!!
|
//resolve user!!!
|
||||||
var senderUser = _userDal.Ctx.Users.FirstOrDefault(x => x.Id == message.SenderId);
|
var senderUser = _userDal.Context.Users.FirstOrDefault(x => x.Id == message.SenderId);
|
||||||
var receiverUser = _userDal.Ctx.Users.FirstOrDefault(x => x.Id == message.ReceiverId);
|
var receiverUser = _userDal.Context.Users.FirstOrDefault(x => x.Id == message.ReceiverId);
|
||||||
string apiKey = _configuration["SendGrid:Key"];
|
string apiKey = _configuration["SendGrid:Key"];
|
||||||
var _client = new SendGridClient(apiKey);
|
var _client = new SendGridClient(apiKey);
|
||||||
var _from = new EmailAddress("", "");
|
var _from = new EmailAddress("", "");
|
||||||
|
|
@ -74,10 +74,10 @@ namespace TIAMWebApp.Server.Services
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_from = new EmailAddress(senderUser.Email, senderUser.Email);
|
_from = new EmailAddress(senderUser.EmailAddress, senderUser.EmailAddress);
|
||||||
}
|
}
|
||||||
var _subject = message.Subject;
|
var _subject = message.Subject;
|
||||||
var _to = new EmailAddress(receiverUser.Email, receiverUser.Email);
|
var _to = new EmailAddress(receiverUser.EmailAddress, receiverUser.EmailAddress);
|
||||||
var _plainTextContent = message.Message;
|
var _plainTextContent = message.Message;
|
||||||
var _htmlContent = message.HtmlContent;
|
var _htmlContent = message.HtmlContent;
|
||||||
var _msg = MailHelper.CreateSingleEmail(_from, _to, message.Subject, _plainTextContent, _htmlContent);
|
var _msg = MailHelper.CreateSingleEmail(_from, _to, message.Subject, _plainTextContent, _htmlContent);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue