Skip to content
Snippets Groups Projects
Commit 6c2389bd authored by esantangelo's avatar esantangelo
Browse files

commit

parent a0b3820d
No related branches found
No related tags found
1 merge request!5Multi tenancy
Showing
with 65 additions and 30 deletions
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
namespace Tsi1.BusinessLayer.Dtos
{
public class CourseCreateDto
{
public string Name { get; set; }
[JsonIgnore]
public int TenantId { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;
namespace Tsi1.BusinessLayer.Dtos
{
......
......@@ -13,5 +13,8 @@ namespace Tsi1.BusinessLayer.Dtos
public int ReceiverId { get; set; }
public string Content { get; set; }
[JsonIgnore]
public int TenantId { get; set; }
}
}
......@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using System.Text.Json.Serialization;
namespace Tsi1.BusinessLayer.Dtos
{
......@@ -28,6 +29,9 @@ namespace Tsi1.BusinessLayer.Dtos
[Required]
public string IdentityCard { get; set; }
[JsonIgnore]
public int TenantId { get; set; }
public int Age { get; set; }
}
}
......@@ -10,7 +10,7 @@ namespace Tsi1.BusinessLayer.Interfaces
{
public interface ICourseService
{
Task<ServiceResult<List<CoursePreviewDto>>> GetCoursePreviews(int userId, string userType);
Task<ServiceResult<List<CoursePreviewDto>>> GetCoursePreviews(string userType, int tenantId);
Task<ServiceResult<Course>> Create(CourseCreateDto newCourse);
}
......
......@@ -13,6 +13,6 @@ namespace Tsi1.BusinessLayer.Interfaces
{
Task<ServiceResult<bool>> SendEmailAsync(MimeMessage message);
Task<ServiceResult<bool>> NotifyNewPostOrMessage(PostCreateDto postCreateDto, List<string> users);
Task<ServiceResult<bool>> NotifyNewPostOrMessage(PostCreateDto postCreateDto, List<string> mails);
}
}
......@@ -9,7 +9,7 @@ namespace Tsi1.BusinessLayer.Interfaces
{
public interface IMessageService
{
Task<ServiceResult<List<MessagePreviewDto>>> GetMessages(int userId, int otherUserId);
Task<ServiceResult<List<MessagePreviewDto>>> GetMessages(int userId, int otherUserId, int tenantId);
Task<ServiceResult<MessagePreviewDto>> Send(MessageCreateDto newMessage);
......
......@@ -10,10 +10,10 @@ namespace Tsi1.BusinessLayer.Interfaces
{
public interface IUserService
{
Task<ServiceResult<User>> Authenticate(string username, string password);
Task<ServiceResult<User>> Authenticate(string username, string password, int tenantId);
Task<ServiceResult<User>> Create(UserRegisterDto dto, string type);
Task<ServiceResult<List<UserPreviewDto>>> GetAll();
Task<ServiceResult<List<UserPreviewDto>>> GetAll(int tenantId);
}
}
......@@ -37,7 +37,7 @@ namespace Tsi1.BusinessLayer.Services
return result;
}
public async Task<ServiceResult<List<CoursePreviewDto>>> GetCoursePreviews(int userId, string userType)
public async Task<ServiceResult<List<CoursePreviewDto>>> GetCoursePreviews(string userType, int tenantId)
{
var result = new ServiceResult<List<CoursePreviewDto>>();
result.Data = new List<CoursePreviewDto>();
......@@ -48,6 +48,7 @@ namespace Tsi1.BusinessLayer.Services
{
courses = await _context.StudentCourses
.Include(x => x.Course)
.Where(x => x.Course.TenantId == tenantId)
.Select(x => x.Course)
.ToListAsync();
}
......@@ -55,6 +56,7 @@ namespace Tsi1.BusinessLayer.Services
{
courses = await _context.ProfessorCourses
.Include(x => x.Course)
.Where(x => x.Course.TenantId == tenantId)
.Select(x => x.Course)
.ToListAsync();
}
......
......@@ -70,13 +70,13 @@ namespace Tsi1.BusinessLayer.Services
return result;
}
public async Task<ServiceResult<bool>> NotifyNewPostOrMessage(PostCreateDto postCreateDto, List<string> users)
public async Task<ServiceResult<bool>> NotifyNewPostOrMessage(PostCreateDto postCreateDto, List<string> mails)
{
var message = new MimeMessage();
foreach (var user in users)
foreach (var mail in mails)
{
message.To.Add(MailboxAddress.Parse(user));
message.To.Add(MailboxAddress.Parse(mail));
}
message.Subject = $"Nuevo Post: {postCreateDto.Title}";
......
......@@ -28,14 +28,14 @@ namespace Tsi1.BusinessLayer.Services
_mapper = mapper;
}
public async Task<ServiceResult<List<MessagePreviewDto>>> GetMessages(int userId, int otherUserId)
public async Task<ServiceResult<List<MessagePreviewDto>>> GetMessages(int userId, int otherUserId, int tenantId)
{
var result = new ServiceResult<List<MessagePreviewDto>>();
var sort = Builders<Message>.Sort.Ascending("Date");
var messages = await _messages.Find(m => (m.SenderId == userId && m.ReceiverId == otherUserId)
|| (m.SenderId == otherUserId && m.ReceiverId == userId))
var messages = await _messages.Find(m => (m.SenderId == userId && m.ReceiverId == otherUserId && m.TenantId == tenantId)
|| (m.SenderId == otherUserId && m.ReceiverId == userId && m.TenantId == tenantId))
.Sort(sort)
.ToListAsync();
......
......@@ -45,7 +45,8 @@ namespace Tsi1.BusinessLayer.Services
{
var result = new ServiceResult<PostMessage>();
var postMessage = await _context.PostMessages.FirstOrDefaultAsync(x => x.Id == postMessageId);
var postMessage = await _context.PostMessages
.FirstOrDefaultAsync(x => x.Id == postMessageId);
if (postMessage == null)
{
......
......@@ -25,13 +25,13 @@ namespace Tsi1.BusinessLayer.Services
_mapper = mapper;
}
public async Task<ServiceResult<User>> Authenticate(string username, string password)
public async Task<ServiceResult<User>> Authenticate(string username, string password, int tenantId)
{
var result = new ServiceResult<User>();
var user = await _context.Users
.Include(x => x.UserType)
.FirstOrDefaultAsync(x => x.Username == username);
.FirstOrDefaultAsync(x => x.Username == username && x.TenantId == tenantId);
if (user == null)
{
......@@ -63,7 +63,8 @@ namespace Tsi1.BusinessLayer.Services
Password = dto.Password,
Email = dto.Email,
FirstName = dto.FirstName,
LastName = dto.LastName
LastName = dto.LastName,
TenantId = dto.TenantId
};
if (type == UserTypes.Student)
......@@ -71,7 +72,8 @@ namespace Tsi1.BusinessLayer.Services
user.Student = new Student()
{
IdentityCard = dto.IdentityCard,
Age = dto.Age
Age = dto.Age,
TenantId = dto.TenantId
};
}
......@@ -79,7 +81,8 @@ namespace Tsi1.BusinessLayer.Services
{
user.Professor = new Professor()
{
IdentityCard = dto.IdentityCard
IdentityCard = dto.IdentityCard,
TenantId = dto.TenantId
};
}
......@@ -90,12 +93,12 @@ namespace Tsi1.BusinessLayer.Services
return result;
}
public async Task<ServiceResult<List<UserPreviewDto>>> GetAll()
public async Task<ServiceResult<List<UserPreviewDto>>> GetAll(int tenantId)
{
var result = new ServiceResult<List<UserPreviewDto>>();
var users = await _context.Users
.Where(x => x.UserType.Name != UserTypes.FacultyAdmin)
.Where(x => x.UserType.Name != UserTypes.FacultyAdmin && x.TenantId == tenantId)
.ToListAsync();
var usersDto = _mapper.Map<List<UserPreviewDto>>(users);
......
......@@ -14,8 +14,13 @@ namespace Tsi1.DataLayer.Entities
}
public int Id { get; set; }
public string Name { get; set; }
public int TenantId { get; set; }
public Tenant Tenant { get; set; }
public ICollection<StudentCourse> StudentCourses { get; set; }
public ICollection<ProfessorCourse> ProfessorCourses { get; set; }
public ICollection<Forum> Forums { get; set; }
......
......@@ -18,10 +18,6 @@ namespace Tsi1.DataLayer.Entities
public int CourseId { get; set; }
public int TenantId { get; set; }
public Tenant Tenant { get; set; }
public Course Course { get; set; }
public ICollection<Post> Posts { get; set; }
......
......@@ -18,7 +18,9 @@ namespace Tsi1.DataLayer.Entities
public string Content { get; set; }
public DateTime Date { get; set; }
public DateTime Date { get; set; }
public int TenantId { get; set; }
}
}
......@@ -13,11 +13,10 @@ namespace Tsi1.DataLayer.Entities
public DateTime Date { get; set; }
public int UserId { get; set; }
public User User { get; set; }
public int PostId { get; set; }
public Post Post { get; set; }
public User User { get; set; }
}
}
......@@ -12,8 +12,12 @@ namespace Tsi1.DataLayer.Entities
}
public int Id { get; set; }
public string IdentityCard { get; set; }
public int TenantId { get; set; }
public Tenant Tenant { get; set; }
public User User { get; set; }
public ICollection<ProfessorCourse> ProfessorCourses { get; set; }
}
......
......@@ -12,9 +12,14 @@ namespace Tsi1.DataLayer.Entities
}
public int Id { get; set; }
public string IdentityCard { get; set; }
public int Age { get; set; }
public int TenantId { get; set; }
public Tenant Tenant { get; set; }
public User User { get; set; }
public ICollection<StudentCourse> StudentCourses { get; set; }
}
......
......@@ -8,13 +8,19 @@ namespace Tsi1.DataLayer.Entities
{
public Tenant()
{
Forums = new HashSet<Forum>();
Courses = new HashSet<Course>();
Professors = new HashSet<Professor>();
Students = new HashSet<Student>();
Users = new HashSet<User>();
}
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Forum> Forums { get; set; }
public ICollection<Course> Courses { get; set; }
public ICollection<Professor> Professors { get; set; }
public ICollection<Student> Students { get; set; }
public ICollection<User> Users { get; set; }
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment