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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ namespace HwProj.Models.CoursesService.ViewModels
{
public enum CriterionType
{
Free = 0
Free = 0,
Deadline = 1
}

public class CriterionViewModel
Expand All @@ -13,5 +14,6 @@ public class CriterionViewModel
public CriterionType Type { get; set; }
[Required] public string Name { get; set; } = null!;
[Range(0, int.MaxValue)] public int MaxPoints { get; set; }
public string? Arguments { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public static HomeworkTaskViewModel ToHomeworkTaskViewModel(this HomeworkTask ta
Id = c.Id,
Type = (CriterionType)c.Type,
Name = c.Name,
MaxPoints = c.MaxPoints
MaxPoints = c.MaxPoints,
Arguments = c.Arguments
})
.ToList(),
};
Expand Down Expand Up @@ -120,7 +121,8 @@ public static CoursePreview ToCoursePreview(this Course course)
Id = criterion.Id,
Type = (Models.CriterionType)criterion.Type,
Name = criterion.Name,
MaxPoints = criterion.MaxPoints
MaxPoints = criterion.MaxPoints,
Arguments = criterion.Arguments
};

public static HomeworkTask ToHomeworkTask(this PostTaskViewModel postTaskViewModel)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HwProj.CoursesService.API.Migrations
{
public partial class CriterionArguments : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Arguments",
table: "Criteria",
type: "nvarchar(max)",
nullable: true);
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Arguments",
table: "Criteria");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<int>("MaxPoints")
.HasColumnType("int");

b.Property<string>("Arguments")
.HasColumnType("nvarchar(max)");

b.Property<string>("Name")
.HasColumnType("nvarchar(max)");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace HwProj.CoursesService.API.Models
{
public enum CriterionType
{
Free = 0
Free = 0,
Deadline = 1
}

public class Criterion : IEntity<long>
Expand All @@ -17,5 +18,6 @@ public class Criterion : IEntity<long>
public CriterionType Type { get; set; }
public string Name { get; set; }
public int MaxPoints { get; set; }
public string? Arguments { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ public bool Equals(Criterion? x, Criterion? y)
x.TaskId == y.TaskId &&
x.Type == y.Type &&
x.Name == y.Name &&
x.MaxPoints == y.MaxPoints;
x.MaxPoints == y.MaxPoints &&
x.Arguments == y.Arguments;
}

public int GetHashCode(Criterion obj) => HashCode.Combine(obj.Id, obj.TaskId, obj.Name);
public int GetHashCode(Criterion obj) => HashCode.Combine(obj.Id, obj.TaskId, obj.Name, obj.Arguments);
}
}
}
11 changes: 11 additions & 0 deletions HwProj.CoursesService/HwProj.CoursesService.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ public void Configure(IApplicationBuilder app, IHostEnvironment env, CourseConte
app.UseEndpoints(x => x.MapControllers());

app.UseDatabase(env, context);
EnsureCriterionArgumentsColumn(context);
}

private static void EnsureCriterionArgumentsColumn(CourseContext context)
{
context.Database.ExecuteSqlRaw(@"
IF OBJECT_ID(N'[Criteria]', N'U') IS NOT NULL
AND COL_LENGTH(N'[Criteria]', N'Arguments') IS NULL
BEGIN
ALTER TABLE [Criteria] ADD [Arguments] nvarchar(max) NULL;
END");
}
}
}
Loading