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
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
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);
newMessage.TenantId = tenantId;
if (userId == newMessage.ReceiverId)
throw new HubException("You cannot send messages to yourself");
......@@ -93,41 +95,18 @@ namespace Tsi1.Api.SignalR
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 connection = new Connection
{
ConnectionId = Context.ConnectionId,
UserId = userId,
};
if (group == null)
{
group = new Group
{
Name = groupName,
};
}
group.Connections.Add(connection);
var result = await _chatService.CreateGroup(group);
var result = await _chatService.CreateGroup(groupName, Context.ConnectionId, userId);
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()
......
......@@ -92,6 +92,9 @@ namespace Tsi1.Api
services.AddScoped<ISectionItemTypeService, SectionItemTypeService>();
services.AddScoped<IDataLoad, DataLoad>();
services.AddScoped<ISurveyService, SurveyService>();
services.AddScoped<IChatService, ChatService>();
services.AddSingleton<PresenceTracker>();
services.Configure<MailSettings>(Configuration.GetSection("MailSettings"));
services.AddScoped<IEmailService, EmailService>();
......
......@@ -36,256 +36,288 @@ namespace Tsi1.BusinessLayer.DataLoad
public async Task LoadDataAsync()
{
//// TENANTS
//var adminTenant = new TenantCreateDto
//{
// Name = TenantAdmin.Name,
//};
//var adminTenantId = await _tenantService.Create(adminTenant);
//var fingTenant = new TenantCreateDto
//{
// Name = "fing",
//};
//var fingTenantId = await _tenantService.Create(fingTenant);
//// USER TYPES
//var udelarAdminUserType = new UserType
//{
// Name = UserTypes.UdelarAdmin,
//};
//_context.Add(udelarAdminUserType);
//var facultyAdminUserType = new UserType
//{
// Name = UserTypes.FacultyAdmin,
//};
//_context.Add(facultyAdminUserType);
//var professorUserType = new UserType
//{
// Name = UserTypes.Professor,
//};
//_context.Add(professorUserType);
//var studentUserType = new UserType
//{
// Name = UserTypes.Student,
//};
//_context.Add(studentUserType);
//await _context.SaveChangesAsync();
//// USERS
//var userAdminUdelar = new UserRegisterDto
//{
// UserTypeId = udelarAdminUserType.Id,
// Username = "admin",
// Password = "admin",
// FirstName = "admin",
// LastName = "admin",
// Email = "admin@mail.com",
// IdentityCard = "12345678-9",
// Age = 44
//};
//await _userService.Create(userAdminUdelar, udelarAdminUserType.Name, adminTenantId.Data.Id);
//var userStudent1 = new UserRegisterDto
//{
// UserTypeId = studentUserType.Id,
// Username = "enzo",
// Password = "enzo",
// FirstName = "Enzo",
// LastName = "Santangelo",
// Email = "enzo@mail.com",
// IdentityCard = "13242344-5",
// Age = 25
//};
//await _userService.Create(userStudent1, studentUserType.Name, fingTenantId.Data.Id);
//var userStudent2 = new UserRegisterDto
//{
// UserTypeId = studentUserType.Id,
// Username = "mathias",
// Password = "mathias",
// FirstName = "Mathias",
// LastName = "Martinez",
// Email = "mathias@mail.com",
// IdentityCard = "3782346-5",
// Age = 26
//};
//await _userService.Create(userStudent2, studentUserType.Name, fingTenantId.Data.Id);
//var userProfessor = new UserRegisterDto
//{
// UserTypeId = professorUserType.Id,
// Username = "prof1",
// Password = "prof1",
// FirstName = "Juan",
// LastName = "Perez",
// Email = "jp@mail.com",
// IdentityCard = "98754342-5",
// Age = 34
//};
//await _userService.Create(userProfessor, professorUserType.Name, fingTenantId.Data.Id);
//var userFingAdmin = new UserRegisterDto
//{
// UserTypeId = facultyAdminUserType.Id,
// Username = "fing",
// Password = "fing",
// FirstName = "fing",
// LastName = "fing",
// Email = "fing@mail.com",
// IdentityCard = "89547821-5",
// Age = 45
//};
//await _userService.Create(userFingAdmin, facultyAdminUserType.Name, fingTenantId.Data.Id);
//// SECTION ITEM TYPES
//var sectionItemTypeFile = new SectionItemType
//{
// Name = SectionItemTypes.File,
//};
//_context.SectionItemTypes.Add(sectionItemTypeFile);
//var sectionItemTypeForum = new SectionItemType
//{
// Name = SectionItemTypes.Forum,
//};
//_context.SectionItemTypes.Add(sectionItemTypeForum);
//var sectionItemTypeSurvey = new SectionItemType
//{
// Name = SectionItemTypes.Survey,
//};
//_context.SectionItemTypes.Add(sectionItemTypeSurvey);
//await _context.SaveChangesAsync();
//// COURSES
//var course1Dto = new CourseCreateDto
//{
// Name = "Calculo 1",
// TenantId = fingTenantId.Data.Id
//};
//var course1 = await _courseService.Create(course1Dto);
//var course2Dto = new CourseCreateDto
//{
// Name = "GAL 1",
// TenantId = fingTenantId.Data.Id
//};
//var course2 = await _courseService.Create(course2Dto);
//var course3Dto = new CourseCreateDto
//{
// Name = "Fisica 1",
// TenantId = fingTenantId.Data.Id
//};
//await _courseService.Create(course3Dto);
//// SECTIONS
//var section1 = new SectionCreateDto
//{
// CourseId = course1.Data.Id,
// Name = "General",
// Order = 1
//};
//var section1Id = await _sectionService.Create(section1);
//var section2 = new SectionCreateDto
//{
// CourseId = course2.Data.Id,
// Name = "General",
// Order = 1
//};
//var section2Id = await _sectionService.Create(section2);
//var section3 = new SectionCreateDto
//{
// CourseId = course1.Data.Id,
// Name = "Tema 1",
// Order = 2
//};
//var section3Id = await _sectionService.Create(section3);
//// SECTION ITEMS
//var sectionItem1 = new SectionItemCreateDto
//{
// SectionId = section1Id.Data,
// Order = 1,
// SectionItemTypeId = sectionItemTypeForum.Id,
// Forum = new ForumCreateDto
// {
// Name = "Novedades"
// }
//};
//await _sectionItemService.Create(sectionItem1);
//var sectionItem2 = new SectionItemCreateDto
//{
// SectionId = section2Id.Data,
// Order = 1,
// SectionItemTypeId = sectionItemTypeForum.Id,
// Forum = new ForumCreateDto
// {
// Name = "Novedades"
// }
//};
//await _sectionItemService.Create(sectionItem2);
//var sectionItem3 = new SectionItemCreateDto
//{
// SectionId = section1Id.Data,
// Order = 2,
// SectionItemTypeId = sectionItemTypeForum.Id,
// Forum = new ForumCreateDto
// {
// Name = "General"
// }
//};
//await _sectionItemService.Create(sectionItem3);
//var sectionItem4 = new SectionItemCreateDto
//{
// SectionId = section3Id.Data,
// Order = 1,
// SectionItemTypeId = sectionItemTypeForum.Id,
// Forum = new ForumCreateDto
// {
// Name = "Tema 1"
// }
//};
//await _sectionItemService.Create(sectionItem4);
//// 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();
// TENANTS
var tenants = new List<Tenant>
{
new Tenant
{
Name = TenantAdmin.Name,
},
new Tenant
{
Name = "fing",
},
};
_context.Tenants.AddRange(tenants);
await _context.SaveChangesAsync();
// USER TYPES
var udelarAdminUserType = new UserType
{
Name = UserTypes.UdelarAdmin,
};
_context.Add(udelarAdminUserType);
var facultyAdminUserType = new UserType
{
Name = UserTypes.FacultyAdmin,
};
_context.Add(facultyAdminUserType);
var professorUserType = new UserType
{
Name = UserTypes.Professor,
};
_context.Add(professorUserType);
var studentUserType = new UserType
{
Name = UserTypes.Student,
};
_context.Add(studentUserType);
await _context.SaveChangesAsync();
// USERS
var users = new List<User>
{
new User
{
UserTypeId = udelarAdminUserType.Id,
Username = "admin",
Password = "admin",
FirstName = "admin",
LastName = "admin",
Email = "admin@mail.com",
TenantId = 1,
},
new User
{
UserTypeId = studentUserType.Id,
Username = "enzo",
Password = "enzo",
FirstName = "Enzo",
LastName = "Santangelo",
Email = "enzo@mail.com",
Student = new Student
{
TenantId = 2,
IdentityCard = "13242344-5",
Age = 25
},
TenantId = 2,
},
new User
{
UserTypeId = studentUserType.Id,
Username = "mathias",
Password = "mathias",
FirstName = "Mathias",
LastName = "Martinez",
Email = "mathias@mail.com",
Student = new Student
{
IdentityCard = "3782346-5",
TenantId = 2,
Age = 26
},
TenantId = 2,
},
new User
{
UserTypeId = professorUserType.Id,
Username = "prof1",
Password = "prof1",
FirstName = "Juan",
LastName = "Perez",
Email = "jp@mail.com",
Professor = new Professor
{
TenantId = 2,
IdentityCard = "98754342-5",
},
TenantId = 2,
},
new User
{
UserTypeId = facultyAdminUserType.Id,
Username = "fing",
Password = "fing",
FirstName = "fing",
LastName = "fing",
Email = "fing@mail.com",
TenantId = 2,
},
};
_context.Users.AddRange(users);
try
{
await _context.SaveChangesAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// SECTION ITEM TYPES
var sectionItemTypeFile = new SectionItemType
{
Name = SectionItemTypes.File,
};
_context.SectionItemTypes.Add(sectionItemTypeFile);
var sectionItemTypeForum = new SectionItemType
{
Name = SectionItemTypes.Forum,
};
_context.SectionItemTypes.Add(sectionItemTypeForum);
var sectionItemTypeSurvey = new SectionItemType
{
Name = SectionItemTypes.Survey,
};
_context.SectionItemTypes.Add(sectionItemTypeSurvey);
await _context.SaveChangesAsync();
// COURSES
var courses = new List<Course>
{
new Course
{
Id = 1,
Name = "Calculo 1",
TenantId = 2
},
new Course
{
Id = 2,
Name = "GAL 1",
TenantId = 2
},
new Course
{
Id = 3,
Name = "Fisica 1",
TenantId = 2
}
};
_context.Courses.AddRange(courses);
await _context.SaveChangesAsync();
// SECTIONS
var section1 = new Section
{
CourseId = 1,
Name = "General",
Order = 1,
SectionItems = new List<SectionItem>
{
new SectionItem
{
Order = 1,
SectionItemTypeId = sectionItemTypeForum.Id,
Forum = new Forum
{
Name = "Novedades"
}
},
new SectionItem
{
Order = 2,
SectionItemTypeId = sectionItemTypeForum.Id,
Forum = new Forum
{
Name = "General"
}
},
}
};
_context.Sections.Add(section1);
var section2 = new Section
{
CourseId = 2,
Name = "General",
Order = 1,
SectionItems = new List<SectionItem>
{
new SectionItem
{
Order = 1,
SectionItemTypeId = sectionItemTypeForum.Id,
Forum = new Forum
{
Name = "Novedades"
}
}
}
};
_context.Sections.Add(section2);
var section3 = new Section
{
CourseId = 1,
Name = "Tema 1",
Order = 2,
SectionItems = new List<SectionItem>
{
new SectionItem
{
Order = 1,
SectionItemTypeId = sectionItemTypeForum.Id,
Forum = new Forum
{
Name = "Tema 1"
}
}
}
};
_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
CreateMap<SurveyResponse, SurveyResponseDetailDto>();
CreateMap<SurveyAnswer, SurveyAnswerDetailDto>();
CreateMap<SurveyAnswer, SurveyAnswerCreateDto>();
CreateMap<AnswerOption, AnswerOptionDetailDto>();
CreateMap<ForumCreateDto, Forum>();
CreateMap<ForumPreviewDto, Forum>();
......@@ -87,6 +88,7 @@ namespace Tsi1.BusinessLayer.Helpers
CreateMap<SurveyResponseDetailDto, SurveyResponse>();
CreateMap<SurveyAnswerDetailDto, SurveyAnswer>();
CreateMap<SurveyAnswerCreateDto, SurveyAnswer>();
CreateMap<AnswerOptionDetailDto, AnswerOption>();
}
}
}
......@@ -11,7 +11,7 @@ namespace Tsi1.BusinessLayer.Interfaces
{
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);
}
......
......@@ -15,5 +15,6 @@ namespace Tsi1.BusinessLayer.Interfaces
Task<ServiceResult<SurveyDetailDto>> GetMySurvey(int surveyId, int userId);
Task<ServiceResult<bool>> Complete(SurveyResponseCreateDto surveyResponse);
Task<ServiceResult<List<SurveyResponseDetailDto>>> GetAllResponses(int surveyId, string userType, int tenantId);
Task<ServiceResult<List<AnswerOptionDetailDto>>> GetAnswerOptions();
}
}
......@@ -18,11 +18,35 @@ namespace Tsi1.BusinessLayer.Services
{
_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
{
await _tsi1Context.SaveChangesAsync();
......@@ -51,6 +75,8 @@ namespace Tsi1.BusinessLayer.Services
if (connection != null)
{
connection.Group = null;
_tsi1Context.Connections.Remove(connection);
await _tsi1Context.SaveChangesAsync();
}
......
......@@ -206,5 +206,16 @@ namespace Tsi1.BusinessLayer.Services
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;
}
}
}