392 lines
9.3 KiB
C#
392 lines
9.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.Http.Headers;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Ease.Core;
|
|
using HRM.BO;
|
|
using HRM.DA;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Payroll.BO;
|
|
using Payroll.Service;
|
|
using IConfiguration = Microsoft.Extensions.Configuration.IConfiguration;
|
|
|
|
namespace HRM.UI.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/LMS")]
|
|
[Authorize]
|
|
public class LMSController : Controller
|
|
{
|
|
#region Declerations
|
|
private readonly IConfiguration _config;
|
|
private readonly IEmployeeService _employeeService;
|
|
private readonly ICourseType _courseTypeService;
|
|
private readonly ICoursesService _coursesService;
|
|
private readonly ILessonsService _lessonsService;
|
|
private readonly ILessonContentService _lessonContentService;
|
|
private readonly IEnrollmentsService _enrollmentService;
|
|
private static string _filePath = @"ClientApp\Documents\";
|
|
#endregion
|
|
|
|
#region Constructor
|
|
public LMSController(IConfiguration config,
|
|
IEmployeeService employeeService, ICourseType courseTypeService,
|
|
ICoursesService courseService, ILessonsService lessonService,
|
|
ILessonContentService lessonContentService, IEnrollmentsService enrollmentService)
|
|
{
|
|
_config = config;
|
|
_employeeService = employeeService;
|
|
_courseTypeService = courseTypeService;
|
|
_coursesService = courseService;
|
|
_lessonsService = lessonService;
|
|
_lessonContentService = lessonContentService;
|
|
_enrollmentService = enrollmentService;
|
|
}
|
|
#endregion
|
|
|
|
#region Functions
|
|
|
|
#region COURSE TYPE
|
|
|
|
#region Save/Update CourseType
|
|
[HttpPost]
|
|
[Route("saveCourseType")]
|
|
public ActionResult saveCourseType(CourseType item)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
int courseTypeID = 0;
|
|
try
|
|
{
|
|
if (item.IsNew == true)
|
|
{
|
|
item.CreatedBy = currentUser.UserID;
|
|
item.CreatedDate = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
item.ModifiedBy = currentUser.UserID;
|
|
item.ModifiedDate = DateTime.Now;
|
|
}
|
|
courseTypeID = _courseTypeService.Save(item);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok(courseTypeID);
|
|
}
|
|
#endregion
|
|
|
|
#region Delete CourseType
|
|
[HttpGet("deleteCourseType/{ID}")]
|
|
public ActionResult DeleteCourseType(int ID)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
try
|
|
{
|
|
_courseTypeService.Delete(ID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
#endregion
|
|
|
|
#region Get By Status
|
|
[HttpGet("getByStatus/{status}")]
|
|
public ActionResult GetByStatus(EnumStatus status)
|
|
{
|
|
List<CourseType> allCourseType = new List<CourseType>();
|
|
try
|
|
{
|
|
allCourseType = _courseTypeService.Get(status);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
return Ok(allCourseType);
|
|
}
|
|
#endregion
|
|
|
|
#region GetAll CourseType
|
|
[HttpGet("getAllCourseType")]
|
|
public ActionResult GetALL()
|
|
{
|
|
List<CourseType> allCourseType = new List<CourseType>();
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
try
|
|
{
|
|
allCourseType = _courseTypeService.GetAll();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok(allCourseType);
|
|
}
|
|
#endregion
|
|
|
|
#region Get CourseType by ParentID
|
|
[HttpGet("getByParentID/{parentID}")]
|
|
public ActionResult GetByParentID(int parentID)
|
|
{
|
|
List<CourseType> allCourseType = new List<CourseType>();
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
try
|
|
{
|
|
allCourseType = _courseTypeService.GetByParent(parentID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
return Ok(allCourseType);
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region COURSES
|
|
|
|
#region Save/Update CourseType
|
|
[HttpPost]
|
|
[Route("saveCourses")]
|
|
public ActionResult saveCourses(Courses item)
|
|
{
|
|
string connectionString = _config.GetSection("dbSettings").GetSection("SqlCommandConnection").Value;
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
int courseTypeID = 0;
|
|
try
|
|
{
|
|
if (item.IsNew == true)
|
|
{
|
|
item.CreatedBy = currentUser.UserID;
|
|
item.CreatedDate = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
item.ModifiedBy = currentUser.UserID;
|
|
item.ModifiedDate = DateTime.Now;
|
|
}
|
|
if (item.CourseTemplate != null)
|
|
{
|
|
item.CourseTemplate.ConnectionString = connectionString;
|
|
}
|
|
courseTypeID = _coursesService.Save(item);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok(courseTypeID);
|
|
}
|
|
#endregion
|
|
|
|
#region Delete Courses
|
|
[HttpGet("deleteCourses/{ID}")]
|
|
public ActionResult deleteCourses(int ID)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
try
|
|
{
|
|
_coursesService.Delete(ID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
#endregion
|
|
|
|
#region Get By Status
|
|
[HttpGet("getCoursesByStatus/{status}")]
|
|
public ActionResult GetCoursesByStatus(EnumStatus status)
|
|
{
|
|
List<Courses> allCourses = new List<Courses>();
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
try
|
|
{
|
|
//allCourses = _coursesService.Get(status);
|
|
allCourses = _coursesService.Get(status, (int)currentUser.UserID);
|
|
|
|
allCourses = allCourses.OrderBy(b => b.Enrollments == null).ThenBy(b => b.CourseProgres?.CompletionPercentage ?? float.MaxValue).ToList();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
return Ok(allCourses);
|
|
}
|
|
#endregion
|
|
|
|
#region Get By ID
|
|
[HttpGet("getCourse/{ID}")]
|
|
public ActionResult GetCourse(int ID)
|
|
{
|
|
Courses oCourse = new Courses();
|
|
try
|
|
{
|
|
oCourse = _coursesService.Get(ID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
return Ok(oCourse);
|
|
}
|
|
#endregion
|
|
|
|
#region Get By ID
|
|
[HttpGet("GetCourseForUser/{ID}")]
|
|
public ActionResult GetCourseForUser(int ID)
|
|
{
|
|
Courses oCourse = new Courses();
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
try
|
|
{
|
|
oCourse = _coursesService.GetCourseForUser(ID, (int)currentUser.UserID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
return Ok(oCourse);
|
|
}
|
|
#endregion
|
|
|
|
#region Get By ID (For Enrollment)
|
|
[HttpGet("GetCourseForEnrollment/{ID}")]
|
|
public ActionResult GetCourseForEnrollment(int ID)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
Courses oCourse = new Courses();
|
|
try
|
|
{
|
|
oCourse = _coursesService.GetForEnrollment(ID, currentUser.UserID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
return Ok(oCourse);
|
|
}
|
|
#endregion
|
|
|
|
#region GetAll CourseType
|
|
[HttpGet("getAllCourses")]
|
|
public ActionResult GetAllCourses()
|
|
{
|
|
List<Courses> allCourses = new List<Courses>();
|
|
try
|
|
{
|
|
allCourses = _coursesService.GetAll();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok(allCourses);
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region LESSONS
|
|
|
|
#region Delete LESSONS
|
|
[HttpGet("deleteLessons/{ID}")]
|
|
public ActionResult deleteLessons(int ID)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
try
|
|
{
|
|
_lessonsService.Delete(ID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
return Ok();
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region LESSONS CONTENT
|
|
|
|
#region Delete LESSONS CONTENT
|
|
[HttpGet("deleteLessonContent/{ID}")]
|
|
public ActionResult DeleteLessonContent(int ID)
|
|
{
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
try
|
|
{
|
|
_lessonContentService.Delete(ID);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok();
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region Enrollments
|
|
|
|
#endregion
|
|
|
|
#region CourseProgress & LessonProgress
|
|
|
|
#region UserCourseProgress
|
|
[HttpPost]
|
|
[Route("UserCourseProgress")]
|
|
public ActionResult UserCourseProgress(Courses item)
|
|
{
|
|
string connectionString = _config.GetSection("dbSettings").GetSection("SqlCommandConnection").Value;
|
|
CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User);
|
|
|
|
Courses oCourses = new Courses();
|
|
try
|
|
{
|
|
oCourses = _coursesService.UserCourseProgress(item);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(StatusCodes.Status500InternalServerError, ex.Message);
|
|
}
|
|
|
|
return Ok(oCourses);
|
|
}
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
}
|