Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ASI.Basecode.Data/Interfaces/IRoomManagementRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using ASI.Basecode.Data.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ASI.Basecode.Data.Interfaces
{
public interface IRoomManagementRepository
{
IEnumerable<RoomManagement> RetrieveAll();
void Add(RoomManagement model);
void Update(RoomManagement model);
void Delete(int RoomId);
}
}
28 changes: 28 additions & 0 deletions ASI.Basecode.Data/Models/RoomManagement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ASI.Basecode.Data.Models
{
public class RoomManagement
{
public int RoomId { get; set; }

public string RoomType { get; set; }

public string RoomCode { get; set; }

public string RoomName { get; set; }

public int RoomCapacity { get; set; }

public string HasEquipments { get; set; }

public string RoomLocation { get; set; }

public string Description { get; set; } // e.g., uses of the room
}
}
49 changes: 49 additions & 0 deletions ASI.Basecode.Data/Repositories/RoomManagementRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using ASI.Basecode.Data.Interfaces;
using ASI.Basecode.Data.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ASI.Basecode.Data.Repositories
{
public class RoomManagementRepository: IRoomManagementRepository
{
private readonly List<RoomManagement> _datasaroom = new List<RoomManagement>();
private int _nextroomId = 1;

public IEnumerable<RoomManagement> RetrieveAll()
{

return _datasaroom;
}

public void Add(RoomManagement model)
{
model.RoomId = _nextroomId++;
_datasaroom.Add(model);
}

public void Update(RoomManagement model)
{
var existingData = _datasaroom.Where(x => x.RoomId == model.RoomId).FirstOrDefault();
if (existingData != null)
{
existingData = model;
}
}

public void Delete(int RoomId)
{
var existingData = _datasaroom.Where(x => x.RoomId == RoomId).FirstOrDefault();
/*if (existingData != null)
{
_datasaroom.Remove(existingData);
}*/

_datasaroom.Remove(existingData);
}
}
}
18 changes: 18 additions & 0 deletions ASI.Basecode.Services/Interfaces/IRoomManagementService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using ASI.Basecode.Data.Models;
using ASI.Basecode.Services.ServiceModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ASI.Basecode.Services.Interfaces
{
public interface IRoomManagementService
{
IEnumerable<RoomManagementViewModel> RetrieveAll();
void Add(RoomManagementViewModel model);
void Update(RoomManagementViewModel model);
void Delete(int RoomId);
}
}
36 changes: 36 additions & 0 deletions ASI.Basecode.Services/ServiceModels/RoomManagementViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using ASI.Basecode.Data.Models;
using ASI.Basecode.Services.ServiceModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ASI.Basecode.Services.ServiceModels
{
public class RoomManagementViewModel
{
[Key]
public int RoomId { get; set; }

[Required]
public string RoomType { get; set; }

[Required]
public string RoomCode { get; set; }

[Required]
public string RoomName { get; set; }

[Required]
public int RoomCapacity { get; set; }

public string HasEquipments { get; set; }

[Required]
public string RoomLocation { get; set; }

public string Description { get; set; } // e.g., uses of the room
}
}
67 changes: 67 additions & 0 deletions ASI.Basecode.Services/Services/RoomManagementService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using ASI.Basecode.Data.Interfaces;
using ASI.Basecode.Data.Repositories;
using ASI.Basecode.Services.ServiceModels;
using ASI.Basecode.Services.Interfaces;
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ASI.Basecode.Data.Models;

namespace ASI.Basecode.Services.Services
{
public class RoomManagementService : IRoomManagementService
{
private readonly List<RoomManagementViewModel> _room = new List<RoomManagementViewModel>();
private readonly IRoomManagementRepository _roomRepository;
private readonly IMapper _mapper;

public RoomManagementService(IRoomManagementRepository RoomManagementRepository, IMapper mapper)
{
_roomRepository = RoomManagementRepository;
_mapper = mapper;
_room.Add(new RoomManagementViewModel { RoomId = 1, RoomName = "Room A", RoomCode = "Room A", RoomType = "Room A", RoomLocation = "First Floor", RoomCapacity = 1 , HasEquipments = "Room A" });

}

public IEnumerable<RoomManagementViewModel> RetrieveAll()
{

var data = _roomRepository.RetrieveAll().Select(s => new RoomManagementViewModel
{
RoomId = s.RoomId,
RoomName = s.RoomName,
RoomCode = s.RoomCode,
RoomType = s.RoomType,
RoomLocation = s.RoomLocation,
RoomCapacity = s.RoomCapacity,
HasEquipments = s.HasEquipments,
});
return data;
}


public void Add(RoomManagementViewModel model)
{
var newModel = new RoomManagement();
_mapper.Map(model, newModel);

_roomRepository.Add(newModel);
}


public void Update(RoomManagementViewModel model)
{
var existingData = _roomRepository.RetrieveAll().Where(s => s.RoomId == model.RoomId).FirstOrDefault();
_mapper.Map(model, existingData);
_roomRepository.Update(existingData);
}

public void Delete(int RoomId)
{
_roomRepository.Delete(RoomId);
}
}
}
42 changes: 42 additions & 0 deletions ASI.Basecode.WebApp/ASI.Basecode.WebApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@
<UserSecretsId>872bac6a-ed64-4226-a559-064bd37b166e</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Views\NewFolder1\**" />
<Compile Remove="Views\NewFolder\**" />
<Compile Remove="Views\Shared\NewFolder\**" />
<Content Remove="Views\NewFolder1\**" />
<Content Remove="Views\NewFolder\**" />
<Content Remove="Views\Shared\NewFolder\**" />
<EmbeddedResource Remove="Views\NewFolder1\**" />
<EmbeddedResource Remove="Views\NewFolder\**" />
<EmbeddedResource Remove="Views\Shared\NewFolder\**" />
<EntityDeploy Remove="Views\NewFolder1\**" />
<EntityDeploy Remove="Views\NewFolder\**" />
<EntityDeploy Remove="Views\Shared\NewFolder\**" />
<None Remove="Views\NewFolder1\**" />
<None Remove="Views\NewFolder\**" />
<None Remove="Views\Shared\NewFolder\**" />
<TypeScriptCompile Remove="Views\NewFolder1\**" />
<TypeScriptCompile Remove="Views\NewFolder\**" />
<TypeScriptCompile Remove="Views\Shared\NewFolder\**" />
</ItemGroup>

<ItemGroup>
<Compile Remove="Controllers\HomeController1.cs" />
<Compile Remove="Controllers\NotifProfileController.cs" />
<Compile Remove="Views\Shared\Index1.cshtml.cs" />
</ItemGroup>

<ItemGroup>
<Content Remove="Views\Shared\Calendar.cshtml" />
<Content Remove="Views\Shared\Component.razor" />
<Content Remove="Views\Shared\Index.cshtml" />
<Content Remove="Views\Shared\Index1.cshtml" />
</ItemGroup>

<ItemGroup>
<None Remove="appsettings.json.rej" />
</ItemGroup>
Expand Down Expand Up @@ -39,4 +73,12 @@
<ItemGroup>
<Folder Include="wwwroot\img\" />
</ItemGroup>

<ItemGroup>
<UpToDateCheckInput Remove="Views\Shared\Calendar.cshtml" />
</ItemGroup>

<ItemGroup>
<_ContentIncludedByDefault Remove="Views\Shared\Calendar.cshtml" />
</ItemGroup>
</Project>
52 changes: 49 additions & 3 deletions ASI.Basecode.WebApp/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class AccountController : ControllerBase<AccountController>
private readonly TokenProviderOptionsFactory _tokenProviderOptionsFactory;
private readonly IConfiguration _appConfiguration;
private readonly IUserService _userService;
private const string AdminUserId = "admin"; // Temporary admin user ID

/// <summary>
/// Initializes a new instance of the <see cref="AccountController"/> class.
Expand Down Expand Up @@ -77,7 +78,7 @@ public ActionResult Login()
/// <param name="model">The model.</param>
/// <param name="returnUrl">The return URL.</param>
/// <returns> Created response view </returns>
[HttpPost]
/*[HttpPost]
[AllowAnonymous]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl)
{
Expand All @@ -92,7 +93,7 @@ public async Task<IActionResult> Login(LoginViewModel model, string returnUrl)

return RedirectToAction("Index", "Home");

/*var loginResult = _userService.AuthenticateUser(model.UserId, model.Password, ref user);
*//*var loginResult = _userService.AuthenticateUser(model.UserId, model.Password, ref user);
if (loginResult == LoginResult.Success)
{
// 認証OK
Expand All @@ -106,7 +107,40 @@ public async Task<IActionResult> Login(LoginViewModel model, string returnUrl)
TempData["ErrorMessage"] = "Incorrect UserId or Password";
return View();
}
return View();*/
return View();*//*
}*/

//the code above being commented is the original login logic of basecode. The code below this comment is the temporary solution for login para mapasok si admin

[HttpPost]
[AllowAnonymous]
public async Task<IActionResult> Login(LoginViewModel model, string returnUrl)
{
this._session.SetString("HasSession", "Exist");

// Temporary login logic
if (model.UserId == AdminUserId && model.Password == "adminpass")
{
// Admin login
User user = new() { Id = 1, UserId = AdminUserId, Name = "Admin User", Password = "adminpass" };
await this._signInManager.SignInAsync(user);
this._session.SetString("UserName", user.Name);
this._session.SetString("UserRole", "Admin");
return RedirectToAction("Index", "Admin");
}
else if (!string.IsNullOrEmpty(model.UserId) && !string.IsNullOrEmpty(model.Password))
{
// Regular user login
User user = new() { Id = 2, UserId = model.UserId, Name = model.UserId, Password = model.Password };
await this._signInManager.SignInAsync(user);
this._session.SetString("UserName", user.Name);
this._session.SetString("UserRole", "User");
return RedirectToAction("Index", "Home");
}

// Invalid login
TempData["ErrorMessage"] = "Incorrect UserId or Password";
return View();
}

[HttpGet]
Expand Down Expand Up @@ -146,5 +180,17 @@ public async Task<IActionResult> SignOutUser()
await this._signInManager.SignOutAsync();
return RedirectToAction("Login", "Account");
}

/// <summary>
/// Sign Out current admin and return login view.
/// </summary>
/// <returns>Created response view</returns>
[AllowAnonymous]
public async Task<IActionResult> SignOutAdmin()
{
await this._signInManager.SignOutAsync();
HttpContext.Session.Clear();
return RedirectToAction("Login", "Account");
}
}
}
Loading