Skip to content
Snippets Groups Projects
Commit 0e937452 authored by esantangelo's avatar esantangelo
Browse files

Merge branch 'develop' into feature/upload-file

# Conflicts:
#	Tsi1.Api/Tsi1.BusinessLayer/Services/TenantService.cs
parents b3af38d9 de014506
No related branches found
No related tags found
3 merge requests!20merge from develop,!16Feature/chat signalr,!15Feature/upload file
...@@ -179,6 +179,9 @@ namespace Tsi1.Api.Controllers ...@@ -179,6 +179,9 @@ namespace Tsi1.Api.Controllers
[HttpPut("Modify/{courseId}")] [HttpPut("Modify/{courseId}")]
public async Task<IActionResult> Modify(int courseId, CourseCreateDto courseDto) public async Task<IActionResult> Modify(int courseId, CourseCreateDto courseDto)
{ {
var tenantId = int.Parse(HttpContext.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
courseDto.TenantId = tenantId;
var result = await _courseService.Modify(courseId, courseDto); var result = await _courseService.Modify(courseId, courseDto);
if (result.HasError) if (result.HasError)
......
...@@ -94,5 +94,33 @@ namespace Tsi1.Api.Controllers ...@@ -94,5 +94,33 @@ namespace Tsi1.Api.Controllers
return Ok(); return Ok();
} }
[Authorize(Roles = UserTypes.UdelarAdmin)]
[HttpGet("FacultyList")]
public async Task<IActionResult> FacultyList()
{
var result = await _tenantService.FacultyList();
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
[Authorize(Roles = UserTypes.UdelarAdmin)]
[HttpGet("CourseList")]
public async Task<IActionResult> CourseList()
{
var result = await _tenantService.CourseList();
if (result.HasError)
{
return BadRequest(result.Message);
}
return Ok(result.Data);
}
} }
} }
...@@ -8,5 +8,6 @@ namespace Tsi1.BusinessLayer.Dtos ...@@ -8,5 +8,6 @@ namespace Tsi1.BusinessLayer.Dtos
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public int StudentQuantity { get; set; }
} }
} }
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class TenantCourseDto
{
public TenantCourseDto()
{
Courses = new List<CoursePreviewDto>();
}
public int Id { get; set; }
public string Name { get; set; }
public List<CoursePreviewDto> Courses { get; set; }
}
}
...@@ -9,5 +9,7 @@ namespace Tsi1.BusinessLayer.Dtos ...@@ -9,5 +9,7 @@ namespace Tsi1.BusinessLayer.Dtos
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public int StudentQuantity { get; set; }
} }
} }
...@@ -29,6 +29,7 @@ namespace Tsi1.BusinessLayer.Helpers ...@@ -29,6 +29,7 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<Course, CoursePreviewDto>(); CreateMap<Course, CoursePreviewDto>();
CreateMap<Tenant, TenantPreviewDto>(); CreateMap<Tenant, TenantPreviewDto>();
CreateMap<Tenant, TenantCreateDto>(); CreateMap<Tenant, TenantCreateDto>();
CreateMap<Tenant, TenantCourseDto>().ForMember(x => x.Courses, opt => opt.Ignore());
CreateMap<UserType, UserTypeDto>(); CreateMap<UserType, UserTypeDto>();
CreateMap<File, FileDto>(); CreateMap<File, FileDto>();
...@@ -49,6 +50,7 @@ namespace Tsi1.BusinessLayer.Helpers ...@@ -49,6 +50,7 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<CoursePreviewDto, Course>(); CreateMap<CoursePreviewDto, Course>();
CreateMap<TenantPreviewDto, Tenant>(); CreateMap<TenantPreviewDto, Tenant>();
CreateMap<TenantCreateDto, Tenant>(); CreateMap<TenantCreateDto, Tenant>();
CreateMap<TenantCourseDto, Tenant>();
CreateMap<UserTypeDto, UserType>(); CreateMap<UserTypeDto, UserType>();
CreateMap<FileDto, File>(); CreateMap<FileDto, File>();
} }
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Helpers
{
public static class TenantAdmin
{
public const string Name = "admin";
}
}
...@@ -20,5 +20,9 @@ namespace Tsi1.BusinessLayer.Interfaces ...@@ -20,5 +20,9 @@ namespace Tsi1.BusinessLayer.Interfaces
Task<ServiceResult<bool>> Modify(int tenantId, TenantCreateDto tenantDto); Task<ServiceResult<bool>> Modify(int tenantId, TenantCreateDto tenantDto);
Task<ServiceResult<bool>> Delete(int tenantId); Task<ServiceResult<bool>> Delete(int tenantId);
Task<ServiceResult<List<TenantPreviewDto>>> FacultyList();
Task<ServiceResult<List<TenantCourseDto>>> CourseList();
} }
} }
using AutoMapper; using AutoMapper;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Tsi1.BusinessLayer.Dtos; using Tsi1.BusinessLayer.Dtos;
...@@ -123,6 +124,58 @@ namespace Tsi1.BusinessLayer.Services ...@@ -123,6 +124,58 @@ namespace Tsi1.BusinessLayer.Services
return result; return result;
} }
public async Task<ServiceResult<List<TenantPreviewDto>>> FacultyList()
{
var result = new ServiceResult<List<TenantPreviewDto>>();
var tenants = await _context.Tenants
.Include(x => x.Students)
.Where(x => x.Name != TenantAdmin.Name)
.ToListAsync();
var tenantDtos = new List<TenantPreviewDto>();
foreach (var tenant in tenants)
{
var tenantDto = _mapper.Map<TenantPreviewDto>(tenant);
tenantDto.StudentQuantity = tenant.Students.Count();
tenantDtos.Add(tenantDto);
}
result.Data = tenantDtos;
return result;
}
public async Task<ServiceResult<List<TenantCourseDto>>> CourseList()
{
var result = new ServiceResult<List<TenantCourseDto>>();
var tenants = await _context.Tenants
.Include(x => x.Courses)
.ThenInclude(x => x.StudentCourses)
.Where(x => x.Name != TenantAdmin.Name)
.ToListAsync();
var tenantDtos = new List<TenantCourseDto>();
foreach (var tenant in tenants)
{
var tenantDto = _mapper.Map<TenantCourseDto>(tenant);
foreach (var course in tenant.Courses)
{
var courseDto = _mapper.Map<CoursePreviewDto>(course);
courseDto.StudentQuantity = course.StudentCourses.Count();
tenantDto.Courses.Add(courseDto);
}
tenantDtos.Add(tenantDto);
}
result.Data = tenantDtos;
return result;
}
public async Task<ServiceResult<int>> GetById(int tenantId) public async Task<ServiceResult<int>> GetById(int tenantId)
{ {
var result = new ServiceResult<int>(); var result = new ServiceResult<int>();
......
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