-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathCourseFilter.cs
More file actions
34 lines (31 loc) · 1.14 KB
/
CourseFilter.cs
File metadata and controls
34 lines (31 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using HwProj.CoursesService.API.Services;
using HwProj.Repositories.Net8;
using Newtonsoft.Json;
namespace HwProj.CoursesService.API.Models
{
public class CourseFilter : IEntity<long>
{
[Key]
public long Id { get; set; }
/// <summary>
/// This field is needed to save the filter in the database in Json format.
/// </summary>
/// <exception cref="InvalidOperationException">
/// There are problems when deserializing data from the database.</exception>
public string FilterJson
{
get => JsonConvert.SerializeObject(Filter, CourseFilterJsonSettings.Settings);
set
{
Filter = JsonConvert.DeserializeObject<Filter>(value, CourseFilterJsonSettings.Settings)
?? throw new InvalidOperationException("The course filter cannot be deserialized.");
Filter.FillEmptyFields();
}
}
[NotMapped]
public Filter Filter { get; set; }
}
}