Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • rodrigo.sastre/tsi1-backend
1 result
Show changes
Commits on Source (4)
...@@ -132,5 +132,14 @@ namespace Tsi1.Api.Controllers ...@@ -132,5 +132,14 @@ namespace Tsi1.Api.Controllers
return Ok(result.Data); return Ok(result.Data);
} }
[Authorize(Roles = UserTypes.FacultyAdmin + ", " + UserTypes.UdelarAdmin + ", " + UserTypes.Professor + ", " + UserTypes.Student)]
[HttpGet("GetAnswerOptions")]
public async Task<IActionResult> GetAnswerOptions()
{
var result = await _surveyService.GetAnswerOptions();
return Ok(result.Data);
}
} }
} }
...@@ -66,6 +66,8 @@ namespace Tsi1.Api.SignalR ...@@ -66,6 +66,8 @@ namespace Tsi1.Api.SignalR
var userId = int.Parse(Context.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); var userId = int.Parse(Context.User.Claims.FirstOrDefault(x => x.Type == "Id").Value);
var tenantId = int.Parse(Context.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value); var tenantId = int.Parse(Context.User.Claims.FirstOrDefault(x => x.Type == "TenantId").Value);
newMessage.TenantId = tenantId;
if (userId == newMessage.ReceiverId) if (userId == newMessage.ReceiverId)
throw new HubException("You cannot send messages to yourself"); throw new HubException("You cannot send messages to yourself");
...@@ -93,41 +95,18 @@ namespace Tsi1.Api.SignalR ...@@ -93,41 +95,18 @@ namespace Tsi1.Api.SignalR
await Clients.Group(groupName).SendAsync("NewMessage", messageDto); await Clients.Group(groupName).SendAsync("NewMessage", messageDto);
} }
private async Task<Group> AddToGroup(string groupName) private async Task<bool> AddToGroup(string groupName)
{ {
var group = await _chatService.GetGroupByName(groupName);
if (group == null)
{
throw new HubException($"No existe el grupo {groupName}");
}
var userId = int.Parse(Context.User.Claims.FirstOrDefault(x => x.Type == "Id").Value); var userId = int.Parse(Context.User.Claims.FirstOrDefault(x => x.Type == "Id").Value);
var connection = new Connection var result = await _chatService.CreateGroup(groupName, Context.ConnectionId, userId);
{
ConnectionId = Context.ConnectionId,
UserId = userId,
};
if (group == null)
{
group = new Group
{
Name = groupName,
};
}
group.Connections.Add(connection);
var result = await _chatService.CreateGroup(group);
if (result.HasError) if (result.HasError)
{ {
throw new HubException($"Error al crear el grupo {group}"); throw new HubException($"Error al crear el grupo {groupName}");
} }
return group; return true;
} }
private async Task<bool> RemoveFromGroup() private async Task<bool> RemoveFromGroup()
......
...@@ -92,6 +92,9 @@ namespace Tsi1.Api ...@@ -92,6 +92,9 @@ namespace Tsi1.Api
services.AddScoped<ISectionItemTypeService, SectionItemTypeService>(); services.AddScoped<ISectionItemTypeService, SectionItemTypeService>();
services.AddScoped<IDataLoad, DataLoad>(); services.AddScoped<IDataLoad, DataLoad>();
services.AddScoped<ISurveyService, SurveyService>(); services.AddScoped<ISurveyService, SurveyService>();
services.AddScoped<IChatService, ChatService>();
services.AddSingleton<PresenceTracker>();
services.Configure<MailSettings>(Configuration.GetSection("MailSettings")); services.Configure<MailSettings>(Configuration.GetSection("MailSettings"));
services.AddScoped<IEmailService, EmailService>(); services.AddScoped<IEmailService, EmailService>();
......
...@@ -36,256 +36,288 @@ namespace Tsi1.BusinessLayer.DataLoad ...@@ -36,256 +36,288 @@ namespace Tsi1.BusinessLayer.DataLoad
public async Task LoadDataAsync() public async Task LoadDataAsync()
{ {
//// TENANTS // TENANTS
//var adminTenant = new TenantCreateDto var tenants = new List<Tenant>
//{ {
// Name = TenantAdmin.Name, new Tenant
//}; {
//var adminTenantId = await _tenantService.Create(adminTenant); Name = TenantAdmin.Name,
},
//var fingTenant = new TenantCreateDto new Tenant
//{ {
// Name = "fing", Name = "fing",
//}; },
//var fingTenantId = await _tenantService.Create(fingTenant); };
_context.Tenants.AddRange(tenants);
//// USER TYPES
//var udelarAdminUserType = new UserType await _context.SaveChangesAsync();
//{
// Name = UserTypes.UdelarAdmin, // USER TYPES
//}; var udelarAdminUserType = new UserType
//_context.Add(udelarAdminUserType); {
Name = UserTypes.UdelarAdmin,
//var facultyAdminUserType = new UserType };
//{ _context.Add(udelarAdminUserType);
// Name = UserTypes.FacultyAdmin,
//}; var facultyAdminUserType = new UserType
//_context.Add(facultyAdminUserType); {
Name = UserTypes.FacultyAdmin,
//var professorUserType = new UserType };
//{ _context.Add(facultyAdminUserType);
// Name = UserTypes.Professor,
//}; var professorUserType = new UserType
//_context.Add(professorUserType); {
Name = UserTypes.Professor,
//var studentUserType = new UserType };
//{ _context.Add(professorUserType);
// Name = UserTypes.Student,
//}; var studentUserType = new UserType
//_context.Add(studentUserType); {
Name = UserTypes.Student,
//await _context.SaveChangesAsync(); };
_context.Add(studentUserType);
//// USERS
//var userAdminUdelar = new UserRegisterDto await _context.SaveChangesAsync();
//{
// UserTypeId = udelarAdminUserType.Id, // USERS
// Username = "admin", var users = new List<User>
// Password = "admin", {
// FirstName = "admin", new User
// LastName = "admin", {
// Email = "admin@mail.com", UserTypeId = udelarAdminUserType.Id,
// IdentityCard = "12345678-9", Username = "admin",
// Age = 44 Password = "admin",
//}; FirstName = "admin",
//await _userService.Create(userAdminUdelar, udelarAdminUserType.Name, adminTenantId.Data.Id); LastName = "admin",
Email = "admin@mail.com",
//var userStudent1 = new UserRegisterDto TenantId = 1,
//{ },
// UserTypeId = studentUserType.Id,
// Username = "enzo", new User
// Password = "enzo", {
// FirstName = "Enzo", UserTypeId = studentUserType.Id,
// LastName = "Santangelo", Username = "enzo",
// Email = "enzo@mail.com", Password = "enzo",
// IdentityCard = "13242344-5", FirstName = "Enzo",
// Age = 25 LastName = "Santangelo",
//}; Email = "enzo@mail.com",
//await _userService.Create(userStudent1, studentUserType.Name, fingTenantId.Data.Id); Student = new Student
{
//var userStudent2 = new UserRegisterDto TenantId = 2,
//{ IdentityCard = "13242344-5",
// UserTypeId = studentUserType.Id, Age = 25
// Username = "mathias", },
// Password = "mathias", TenantId = 2,
// FirstName = "Mathias", },
// LastName = "Martinez",
// Email = "mathias@mail.com", new User
// IdentityCard = "3782346-5", {
// Age = 26 UserTypeId = studentUserType.Id,
//}; Username = "mathias",
//await _userService.Create(userStudent2, studentUserType.Name, fingTenantId.Data.Id); Password = "mathias",
FirstName = "Mathias",
//var userProfessor = new UserRegisterDto LastName = "Martinez",
//{ Email = "mathias@mail.com",
// UserTypeId = professorUserType.Id, Student = new Student
// Username = "prof1", {
// Password = "prof1", IdentityCard = "3782346-5",
// FirstName = "Juan", TenantId = 2,
// LastName = "Perez", Age = 26
// Email = "jp@mail.com", },
// IdentityCard = "98754342-5", TenantId = 2,
// Age = 34 },
//};
//await _userService.Create(userProfessor, professorUserType.Name, fingTenantId.Data.Id); new User
{
//var userFingAdmin = new UserRegisterDto UserTypeId = professorUserType.Id,
//{ Username = "prof1",
// UserTypeId = facultyAdminUserType.Id, Password = "prof1",
// Username = "fing", FirstName = "Juan",
// Password = "fing", LastName = "Perez",
// FirstName = "fing", Email = "jp@mail.com",
// LastName = "fing", Professor = new Professor
// Email = "fing@mail.com", {
// IdentityCard = "89547821-5", TenantId = 2,
// Age = 45 IdentityCard = "98754342-5",
//}; },
//await _userService.Create(userFingAdmin, facultyAdminUserType.Name, fingTenantId.Data.Id); TenantId = 2,
},
//// SECTION ITEM TYPES
//var sectionItemTypeFile = new SectionItemType new User
//{ {
// Name = SectionItemTypes.File, UserTypeId = facultyAdminUserType.Id,
//}; Username = "fing",
//_context.SectionItemTypes.Add(sectionItemTypeFile); Password = "fing",
FirstName = "fing",
//var sectionItemTypeForum = new SectionItemType LastName = "fing",
//{ Email = "fing@mail.com",
// Name = SectionItemTypes.Forum, TenantId = 2,
//}; },
//_context.SectionItemTypes.Add(sectionItemTypeForum); };
//var sectionItemTypeSurvey = new SectionItemType _context.Users.AddRange(users);
//{
// Name = SectionItemTypes.Survey, try
//}; {
//_context.SectionItemTypes.Add(sectionItemTypeSurvey); await _context.SaveChangesAsync();
}
//await _context.SaveChangesAsync(); catch (Exception ex)
{
//// COURSES
//var course1Dto = new CourseCreateDto Console.WriteLine(ex.Message);
//{ }
// Name = "Calculo 1",
// TenantId = fingTenantId.Data.Id // SECTION ITEM TYPES
//}; var sectionItemTypeFile = new SectionItemType
//var course1 = await _courseService.Create(course1Dto); {
Name = SectionItemTypes.File,
//var course2Dto = new CourseCreateDto };
//{ _context.SectionItemTypes.Add(sectionItemTypeFile);
// Name = "GAL 1",
// TenantId = fingTenantId.Data.Id var sectionItemTypeForum = new SectionItemType
//}; {
//var course2 = await _courseService.Create(course2Dto); Name = SectionItemTypes.Forum,
};
//var course3Dto = new CourseCreateDto _context.SectionItemTypes.Add(sectionItemTypeForum);
//{
// Name = "Fisica 1", var sectionItemTypeSurvey = new SectionItemType
// TenantId = fingTenantId.Data.Id {
//}; Name = SectionItemTypes.Survey,
//await _courseService.Create(course3Dto); };
_context.SectionItemTypes.Add(sectionItemTypeSurvey);
//// SECTIONS
//var section1 = new SectionCreateDto await _context.SaveChangesAsync();
//{
// CourseId = course1.Data.Id, // COURSES
// Name = "General", var courses = new List<Course>
// Order = 1 {
//}; new Course
//var section1Id = await _sectionService.Create(section1); {
Id = 1,
//var section2 = new SectionCreateDto Name = "Calculo 1",
//{ TenantId = 2
// CourseId = course2.Data.Id, },
// Name = "General",
// Order = 1 new Course
//}; {
//var section2Id = await _sectionService.Create(section2); Id = 2,
Name = "GAL 1",
//var section3 = new SectionCreateDto TenantId = 2
//{ },
// CourseId = course1.Data.Id,
// Name = "Tema 1", new Course
// Order = 2 {
//}; Id = 3,
//var section3Id = await _sectionService.Create(section3); Name = "Fisica 1",
TenantId = 2
//// SECTION ITEMS }
//var sectionItem1 = new SectionItemCreateDto };
//{
// SectionId = section1Id.Data, _context.Courses.AddRange(courses);
// Order = 1,
// SectionItemTypeId = sectionItemTypeForum.Id, await _context.SaveChangesAsync();
// Forum = new ForumCreateDto
// {
// Name = "Novedades" // SECTIONS
// } var section1 = new Section
//}; {
//await _sectionItemService.Create(sectionItem1); CourseId = 1,
Name = "General",
//var sectionItem2 = new SectionItemCreateDto Order = 1,
//{ SectionItems = new List<SectionItem>
// SectionId = section2Id.Data, {
// Order = 1, new SectionItem
// SectionItemTypeId = sectionItemTypeForum.Id, {
// Forum = new ForumCreateDto Order = 1,
// { SectionItemTypeId = sectionItemTypeForum.Id,
// Name = "Novedades" Forum = new Forum
// } {
//}; Name = "Novedades"
//await _sectionItemService.Create(sectionItem2); }
},
//var sectionItem3 = new SectionItemCreateDto new SectionItem
//{ {
// SectionId = section1Id.Data, Order = 2,
// Order = 2, SectionItemTypeId = sectionItemTypeForum.Id,
// SectionItemTypeId = sectionItemTypeForum.Id, Forum = new Forum
// Forum = new ForumCreateDto {
// { Name = "General"
// Name = "General" }
// } },
//}; }
//await _sectionItemService.Create(sectionItem3); };
_context.Sections.Add(section1);
//var sectionItem4 = new SectionItemCreateDto
//{ var section2 = new Section
// SectionId = section3Id.Data, {
// Order = 1, CourseId = 2,
// SectionItemTypeId = sectionItemTypeForum.Id, Name = "General",
// Forum = new ForumCreateDto Order = 1,
// { SectionItems = new List<SectionItem>
// Name = "Tema 1" {
// } new SectionItem
//}; {
//await _sectionItemService.Create(sectionItem4);
Order = 1,
//// ANSWER OPTIONS SectionItemTypeId = sectionItemTypeForum.Id,
//var answerOptions = new List<AnswerOption> Forum = new Forum
//{ {
// new AnswerOption Name = "Novedades"
// { }
// Name = "Excelente" }
// }, }
// new AnswerOption };
// { _context.Sections.Add(section2);
// Name = "Conforme"
// }, var section3 = new Section
// new AnswerOption {
// { CourseId = 1,
// Name = "Neutro" Name = "Tema 1",
// }, Order = 2,
// new AnswerOption SectionItems = new List<SectionItem>
// { {
// Name = "No Conforme" new SectionItem
// }, {
// new AnswerOption Order = 1,
// { SectionItemTypeId = sectionItemTypeForum.Id,
// Name = "Mal" Forum = new Forum
// }, {
//}; Name = "Tema 1"
}
//_context.AnswerOptions.AddRange(answerOptions); }
//await _context.SaveChangesAsync(); }
};
_context.Sections.Add(section3);
await _context.SaveChangesAsync();
// ANSWER OPTIONS
var answerOptions = new List<AnswerOption>
{
new AnswerOption
{
Name = "Excelente"
},
new AnswerOption
{
Name = "Conforme"
},
new AnswerOption
{
Name = "Neutro"
},
new AnswerOption
{
Name = "No Conforme"
},
new AnswerOption
{
Name = "Mal"
},
};
_context.AnswerOptions.AddRange(answerOptions);
await _context.SaveChangesAsync();
} }
} }
......
using System;
using System.Collections.Generic;
using System.Text;
namespace Tsi1.BusinessLayer.Dtos
{
public class AnswerOptionDetailDto
{
public int Id { get; set; }
public string Name { get; set; }
}
}
...@@ -49,6 +49,7 @@ namespace Tsi1.BusinessLayer.Helpers ...@@ -49,6 +49,7 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<SurveyResponse, SurveyResponseDetailDto>(); CreateMap<SurveyResponse, SurveyResponseDetailDto>();
CreateMap<SurveyAnswer, SurveyAnswerDetailDto>(); CreateMap<SurveyAnswer, SurveyAnswerDetailDto>();
CreateMap<SurveyAnswer, SurveyAnswerCreateDto>(); CreateMap<SurveyAnswer, SurveyAnswerCreateDto>();
CreateMap<AnswerOption, AnswerOptionDetailDto>();
CreateMap<ForumCreateDto, Forum>(); CreateMap<ForumCreateDto, Forum>();
CreateMap<ForumPreviewDto, Forum>(); CreateMap<ForumPreviewDto, Forum>();
...@@ -87,6 +88,7 @@ namespace Tsi1.BusinessLayer.Helpers ...@@ -87,6 +88,7 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<SurveyResponseDetailDto, SurveyResponse>(); CreateMap<SurveyResponseDetailDto, SurveyResponse>();
CreateMap<SurveyAnswerDetailDto, SurveyAnswer>(); CreateMap<SurveyAnswerDetailDto, SurveyAnswer>();
CreateMap<SurveyAnswerCreateDto, SurveyAnswer>(); CreateMap<SurveyAnswerCreateDto, SurveyAnswer>();
CreateMap<AnswerOptionDetailDto, AnswerOption>();
} }
} }
} }
...@@ -11,7 +11,7 @@ namespace Tsi1.BusinessLayer.Interfaces ...@@ -11,7 +11,7 @@ namespace Tsi1.BusinessLayer.Interfaces
{ {
Task<Group> GetGroupByName(string groupName); Task<Group> GetGroupByName(string groupName);
Task<ServiceResult<Group>> CreateGroup(Group group); Task<ServiceResult<bool>> CreateGroup(string groupName, string connectionId, int userId);
Task<bool> RemoveConnectionFromGroup(string connectionId); Task<bool> RemoveConnectionFromGroup(string connectionId);
} }
......
...@@ -15,5 +15,6 @@ namespace Tsi1.BusinessLayer.Interfaces ...@@ -15,5 +15,6 @@ namespace Tsi1.BusinessLayer.Interfaces
Task<ServiceResult<SurveyDetailDto>> GetMySurvey(int surveyId, int userId); Task<ServiceResult<SurveyDetailDto>> GetMySurvey(int surveyId, int userId);
Task<ServiceResult<bool>> Complete(SurveyResponseCreateDto surveyResponse); Task<ServiceResult<bool>> Complete(SurveyResponseCreateDto surveyResponse);
Task<ServiceResult<List<SurveyResponseDetailDto>>> GetAllResponses(int surveyId, string userType, int tenantId); Task<ServiceResult<List<SurveyResponseDetailDto>>> GetAllResponses(int surveyId, string userType, int tenantId);
Task<ServiceResult<List<AnswerOptionDetailDto>>> GetAnswerOptions();
} }
} }
...@@ -18,11 +18,35 @@ namespace Tsi1.BusinessLayer.Services ...@@ -18,11 +18,35 @@ namespace Tsi1.BusinessLayer.Services
{ {
_tsi1Context = tsi1Context; _tsi1Context = tsi1Context;
} }
public async Task<ServiceResult<Group>> CreateGroup(Group group)
public async Task<ServiceResult<bool>> CreateGroup(string groupName, string connectionId, int userId)
{ {
var result = new ServiceResult<Group>(); var result = new ServiceResult<bool>();
var existingGroup = true;
var group = await this.GetGroupByName(groupName);
if (group == null)
{
existingGroup = false;
group = new Group
{
Name = groupName,
};
}
_tsi1Context.Groups.Add(group); var connection = new Connection
{
ConnectionId = connectionId,
UserId = userId,
};
group.Connections.Add(connection);
if (!existingGroup)
{
_tsi1Context.Groups.Add(group);
}
try try
{ {
await _tsi1Context.SaveChangesAsync(); await _tsi1Context.SaveChangesAsync();
...@@ -51,6 +75,8 @@ namespace Tsi1.BusinessLayer.Services ...@@ -51,6 +75,8 @@ namespace Tsi1.BusinessLayer.Services
if (connection != null) if (connection != null)
{ {
connection.Group = null; connection.Group = null;
_tsi1Context.Connections.Remove(connection);
await _tsi1Context.SaveChangesAsync(); await _tsi1Context.SaveChangesAsync();
} }
......
...@@ -206,5 +206,16 @@ namespace Tsi1.BusinessLayer.Services ...@@ -206,5 +206,16 @@ namespace Tsi1.BusinessLayer.Services
return result; return result;
} }
public async Task<ServiceResult<List<AnswerOptionDetailDto>>> GetAnswerOptions()
{
var result = new ServiceResult<List<AnswerOptionDetailDto>>();
var answerOptions = await _context.AnswerOptions.AsNoTracking().ToListAsync();
result.Data = _mapper.Map<List<AnswerOptionDetailDto>>(answerOptions);
return result;
}
} }
} }