Skip to content

Commit

Permalink
update Config.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
PhucNghi176 committed Nov 11, 2024
1 parent 212126d commit 25ce619
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public async Task<Result> Handle(Command.GeneratePoints request, CancellationTok
{
var users = await _userRepository.FindAll(x => x.Role == 0 && x.Status == 1).AsTracking()
.ToListAsync(cancellationToken);
var point = await _context.Configs.Where(x => x.Key.Equals("PointPerStudent")).Select(x => x.Value)
var pointString = await _context.Configs.Where(x => x.Key.Equals("PointPerStudent")).Select(x => x.Value)
.FirstOrDefaultAsync(cancellationToken);
var point = double.Parse(pointString!);
foreach (var x in users)
{
x.Points = point;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task<Result> Handle(Command.CreateScheduleCommand request, Cancella
return Result.Failure(new Error("500", "Booking points is not exist !"));
}

if (group.BookingPoints < point!.Value)
if (group.BookingPoints < double.Parse(point!.Value))
{
return Result.Failure(new Error("500", "Not enough points to book"));
}
Expand All @@ -118,7 +118,7 @@ public async Task<Result> Handle(Command.CreateScheduleCommand request, Cancella
scheduleRepository.Add(schedule);
if (isAccepted == 1)
{
group.BookingPoints -= point.Value;
group.BookingPoints -= double.Parse(point!.Value);
}


Expand All @@ -127,7 +127,7 @@ public async Task<Result> Handle(Command.CreateScheduleCommand request, Cancella
UserId = x.StudentId,
ScheduleId = schedule.Id,
Date = schedule.Date,
Point = point.Value / group.Members.Count,
Point = double.Parse(point!.Value) / group.Members.Count,
Status = 0
}).ToList();

Expand Down
2 changes: 1 addition & 1 deletion MBS_COMMAND.Domain/Entities/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public class Config
{
[Key]
public string Key { get; set; }
public int Value { get; set; }
public string Value { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("Key")
.HasColumnType("nvarchar(450)");

b.Property<int>("Value")
.HasColumnType("int");
b.Property<string>("Value")
.IsRequired()
.HasColumnType("nvarchar(max)");

b.HasKey("Key");

Expand Down

0 comments on commit 25ce619

Please sign in to comment.