diff --git a/Areas/OTcalculate/Controllers/HrDashboardController.cs b/Areas/OTcalculate/Controllers/HrDashboardController.cs index 72bcf1e..177fe9c 100644 --- a/Areas/OTcalculate/Controllers/HrDashboardController.cs +++ b/Areas/OTcalculate/Controllers/HrDashboardController.cs @@ -19,23 +19,6 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Controllers _context = context; } - [HttpGet] - public async Task GetRateList() - { - var users = await _context.Users - .Where(u => u.Id != 1 && u.Id != 2) - .Include(u => u.Department) - .Select(u => new RateModel - { - Id = u.Id.ToString(), - FullName = u.FullName, - departmentId = u.departmentId, - DepartmentName = u.Department != null ? u.Department.DepartmentName : "N/A" - }) - .ToListAsync(); - - return Json(users); - } public IActionResult Rate() { @@ -56,5 +39,73 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Controllers { return View(); } + + #region Rates + [HttpPost("UpdateRates")] + public async Task UpdateRate([FromBody] List rates) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + try + { + foreach (var Rate in rates) + { + var existingRate = await _context.Rates.FindAsync(Rate.RateId); + if (existingRate != null) + { + existingRate.RateValue = Rate.RateValue; + _context.Rates.Update(existingRate); + } + } + + await _context.SaveChangesAsync(); + + var updateRates = await _context.Rates + .Include(rates => rates.Users) + .Select(rates => new + { + rates.RateId, + rates.RateValue, + rates.UserId, + FullName = rates.Users.FullName, + DepartmentName = rates.Users.DepartmentName + }) + .ToListAsync(); + + return Json(updateRates); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("GetUserRates")] + public async Task GetUserRates() + { + try + { + var userRates = await _context.Rates + .Include(rates => rates.Users) + .Select(rates => new + { + rates.RateId, + rates.RateValue, + rates.UserId, + FullName = rates.Users.FullName, + DepartmentName = rates.Users.DepartmentName + }) + .ToListAsync(); + + return Json(userRates); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + #endregion } } diff --git a/Areas/OTcalculate/Models/RateModel.cs b/Areas/OTcalculate/Models/RateModel.cs index e3b7658..1a46309 100644 --- a/Areas/OTcalculate/Models/RateModel.cs +++ b/Areas/OTcalculate/Models/RateModel.cs @@ -7,16 +7,15 @@ namespace PSTW_CentralSystem.Areas.OTcalculate.Models public class RateModel { [Key] - public required string Id { get; set; } + public int RateId { get; set; } - public required string FullName { get; set; } + public decimal RateValue { get; set; } - public int? departmentId { get; set; } + public int UserId { get; set; } - [ForeignKey("departmentId")] - public virtual DepartmentModel? Department { get; set; } + [ForeignKey("UserId")] - public string? DepartmentName { get; set; } + public virtual UserModel? Users { get; set; } } } diff --git a/Areas/OTcalculate/Views/HrDashboard/Rate.cshtml b/Areas/OTcalculate/Views/HrDashboard/Rate.cshtml index 828fb36..aaf0c27 100644 --- a/Areas/OTcalculate/Views/HrDashboard/Rate.cshtml +++ b/Areas/OTcalculate/Views/HrDashboard/Rate.cshtml @@ -46,38 +46,45 @@
-
-

UPDATE RATE

-
+
+

UPDATE RATE

+
@* Enter Rate *@ -
+
- +
+ @* User Table Rate *@
-
-
-
-
-
-
-
-
-
-
-
-
-
+ + + + + + + + + + + + + + + +
Full NameDepartmentSelect Rate
{{ user.FullName }}{{ user.DepartmentName }} + +
+
@@ -93,54 +100,32 @@ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }