diff --git a/OutOfSchool/OutOfSchool.DataAccess/Extensions/ModelBuilderExtension.cs b/OutOfSchool/OutOfSchool.DataAccess/Extensions/ModelBuilderExtension.cs index 4fbd97bd1d..62c098107f 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Extensions/ModelBuilderExtension.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Extensions/ModelBuilderExtension.cs @@ -88,6 +88,43 @@ public static void Seed(this ModelBuilder builder) Description = "provider admin permissions", } ); + + builder.Entity().HasData( + new AchievementType + { + Id = 1L, + Title = "Переможці міжнародних та всеукраїнських спортивних змагань (індивідуальних та командних)", + }, + new AchievementType + { + Id = 2L, + Title = "Призери та учасники міжнародних, всеукраїнських та призери регіональних конкурсів і виставок наукових, технічних, дослідницьких, інноваційних, ІТ проектів", + }, + new AchievementType + { + Id = 3L, + Title = "Реципієнти міжнародних грантів", + }, + new AchievementType + { + Id = 4L, + Title = "Призери міжнародних культурних конкурсів та фестивалів", + }, + new AchievementType + { + Id = 5L, + Title = "Соціально активні категорії учнів", + }, + new AchievementType + { + Id = 6L, + Title = "Цифрові інструменти Google для закладів вищої та фахової передвищої освіти", + }, + new AchievementType + { + Id = 7L, + Title = "Переможці та учасники олімпіад міжнародного та всеукраїнського рівнів", + }); } /// diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Achievement.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Achievement.cs new file mode 100644 index 0000000000..8d32231319 --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Achievement.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace OutOfSchool.Services.Models +{ + public class Achievement : IKeyedEntity + { + public Guid Id { get; set; } + + [Required] + [DataType(DataType.Text)] + [MaxLength(2000)] + [MinLength(1)] + public string Title { get; set; } + + [Required] + [DataType(DataType.Date)] + [Column(TypeName = "date")] + public DateTime AchievementDate { get; set; } = default; + + [Required] + public Guid WorkshopId { get; set; } + + public virtual Workshop Workshop { get; set; } + + [Required] + public long AchievementTypeId { get; set; } + + public virtual AchievementType AchievementType { get; set; } + + public virtual List Children { get; set; } + + public virtual List Teachers { get; set; } + } +} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/AchievementTeacher.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/AchievementTeacher.cs new file mode 100644 index 0000000000..a5ebae1d77 --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/AchievementTeacher.cs @@ -0,0 +1,21 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace OutOfSchool.Services.Models +{ + public class AchievementTeacher : IKeyedEntity + { + public long Id { get; set; } + + [Required] + public Guid AchievementId { get; set; } + + public virtual Achievement Achievement { get; set; } + + [Required] + [DataType(DataType.Text)] + [MaxLength(100)] + [MinLength(1)] + public string Title { get; set; } + } +} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/AchievementType.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/AchievementType.cs new file mode 100644 index 0000000000..25c8ff3a52 --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/AchievementType.cs @@ -0,0 +1,16 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace OutOfSchool.Services.Models +{ + public class AchievementType : IKeyedEntity + { + public long Id { get; set; } + + [Required] + [DataType(DataType.Text)] + [MaxLength(200)] + [MinLength(1)] + public string Title { get; set; } + } +} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Child.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Child.cs index b67dbd7a69..8accdc09bc 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/Child.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Child.cs @@ -28,5 +28,7 @@ public class Child : IKeyedEntity public virtual ICollection SocialGroups { get; set; } public virtual List ChildSocialGroups { get; set; } + + public virtual List Achievements { get; set; } } } diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/AchievementConfiguration.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/AchievementConfiguration.cs new file mode 100644 index 0000000000..f7c4db5461 --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/AchievementConfiguration.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace OutOfSchool.Services.Models.Configurations +{ + internal class AchievementConfiguration : IEntityTypeConfiguration + { + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(x => x.Id); + + builder.HasOne(x => x.AchievementType) + .WithMany() + .IsRequired() + .HasForeignKey(x => x.AchievementTypeId) + .OnDelete(DeleteBehavior.NoAction); + + builder.HasMany(x => x.Children) + .WithMany(x => x.Achievements); + } + } +} diff --git a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs index a1bbb03c26..1c94e3a352 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs @@ -94,6 +94,12 @@ public OutOfSchoolDbContext(DbContextOptions options) public DbSet Codeficators { get; set; } + public DbSet AchievementTypes { get; set; } + + public DbSet AchievementTeachers { get; set; } + + public DbSet Achievements { get; set; } + public async Task CompleteAsync() => await this.SaveChangesAsync(); public int Complete() => this.SaveChanges(); @@ -116,6 +122,7 @@ protected override void OnModelCreating(ModelBuilder builder) builder.ApplyConfiguration(new WorkshopConfiguration()); builder.ApplyConfiguration(new EntityImagesConfiguration()); builder.ApplyConfiguration(new NotificationConfiguration()); + builder.ApplyConfiguration(new AchievementConfiguration()); builder.Seed(); builder.UpdateIdentityTables(); diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/AchievementRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/AchievementRepository.cs new file mode 100644 index 0000000000..9fa2bf12ac --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/AchievementRepository.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using OutOfSchool.Services.Models; + +namespace OutOfSchool.Services.Repository +{ + /// + /// Repository for accessing the Achievement table in database. + /// + public class AchievementRepository : EntityRepositoryBase, IAchievementRepository + { + /// + /// Initializes a new instance of the class. + /// + /// OutOfSchoolDbContext. + public AchievementRepository(OutOfSchoolDbContext dbContext) + : base(dbContext) + { + } + + /// + /// Get elements by Workshop Id. + /// + /// GUID Workshop Id. + /// /// A representing the result of the asynchronous operation. + public async Task> GetByWorkshopId(Guid workshopId) + { + var achievements = dbSet.Where(a => a.WorkshopId == workshopId); + + return await Task.FromResult(achievements); + } + + /// + /// Add new element. + /// + /// Entity to create. + /// GUID List of Children. + /// String List of Teachers. + /// A representing the result of the asynchronous operation. + public async Task Create(Achievement achievement, List childrenIDs, List teachers) + { + achievement.Children = dbContext.Children.Where(w => childrenIDs.Contains(w.Id)) + .ToList(); + + achievement.Teachers = new List(); + + foreach (string teacher in teachers) + { + achievement.Teachers.Add(new AchievementTeacher { Title = teacher, Achievement = achievement }); + } + + await dbSet.AddAsync(achievement); + await dbContext.SaveChangesAsync(); + + return await Task.FromResult(achievement); + } + + /// + /// Update information about element. + /// + /// Entity to update. + /// GUID List of Children. + /// String List of Teachers. + /// A representing the result of the asynchronous operation. + public async Task Update(Achievement achievement, List childrenIDs, List teachers) + { + var newAchievement = dbSet.Find(achievement.Id); + + dbContext.Entry(newAchievement).CurrentValues.SetValues(achievement); + + newAchievement.Children.RemoveAll(x => !childrenIDs.Contains(x.Id)); + var exceptChildrenIDs = childrenIDs.Where(p => newAchievement.Children.All(x => x.Id != p)); + newAchievement.Children.AddRange(dbContext.Children.Where(w => exceptChildrenIDs.Contains(w.Id)).ToList()); + + newAchievement.Teachers.RemoveAll(x => !teachers.Contains(x.Title)); + + var exceptTeachers = teachers.Where(p => newAchievement.Teachers.All(x => !x.Title.Equals(p))); + foreach (var teacher in exceptTeachers) + { + newAchievement.Teachers.Add(new AchievementTeacher { Title = teacher, Achievement = newAchievement }); + } + + dbContext.Entry(newAchievement).State = EntityState.Modified; + + await this.dbContext.SaveChangesAsync(); + return newAchievement; + } + + } +} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/IAchievementRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/IAchievementRepository.cs new file mode 100644 index 0000000000..788fe9587d --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/IAchievementRepository.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using OutOfSchool.Services.Models; + +namespace OutOfSchool.Services.Repository +{ + public interface IAchievementRepository : IEntityRepositoryBase + { + Task> GetByWorkshopId(Guid workshopId); + + Task Create(Achievement achievement, List childrenIDs, List teachers); + + Task Update(Achievement entity, List childrenIDs, List teachers); + } +} diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20220621091438_Achievements.Designer.cs b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20220621091438_Achievements.Designer.cs new file mode 100644 index 0000000000..19a60f4572 --- /dev/null +++ b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20220621091438_Achievements.Designer.cs @@ -0,0 +1,2028 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OutOfSchool.Services; + +namespace OutOfSchool.IdentityServer.Data.Migrations.OutOfSchoolMigrations +{ + [DbContext(typeof(OutOfSchoolDbContext))] + [Migration("20220621091438_Achievements")] + partial class Achievements + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 64) + .HasAnnotation("ProductVersion", "5.0.11"); + + modelBuilder.Entity("AchievementChild", b => + { + b.Property("AchievementsId") + .HasColumnType("binary(16)"); + + b.Property("ChildrenId") + .HasColumnType("binary(16)"); + + b.HasKey("AchievementsId", "ChildrenId"); + + b.HasIndex("ChildrenId"); + + b.ToTable("AchievementChild"); + }); + + modelBuilder.Entity("DirectionInstitutionHierarchy", b => + { + b.Property("DirectionsId") + .HasColumnType("bigint"); + + b.Property("InstitutionHierarchiesId") + .HasColumnType("binary(16)"); + + b.HasKey("DirectionsId", "InstitutionHierarchiesId"); + + b.HasIndex("InstitutionHierarchiesId"); + + b.ToTable("DirectionInstitutionHierarchy"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("FriendlyName") + .HasColumnType("longtext"); + + b.Property("Xml") + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("DataProtectionKeys"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("longtext"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("ClaimType") + .HasColumnType("longtext"); + + b.Property("ClaimValue") + .HasColumnType("longtext"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("ClaimType") + .HasColumnType("longtext"); + + b.Property("ClaimValue") + .HasColumnType("longtext"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("varchar(255)"); + + b.Property("ProviderKey") + .HasColumnType("varchar(255)"); + + b.Property("ProviderDisplayName") + .HasColumnType("longtext"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("varchar(255)"); + + b.Property("RoleId") + .HasColumnType("varchar(255)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("varchar(255)"); + + b.Property("LoginProvider") + .HasColumnType("varchar(255)"); + + b.Property("Name") + .HasColumnType("varchar(255)"); + + b.Property("Value") + .HasColumnType("longtext"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Achievement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("AchievementDate") + .HasColumnType("date"); + + b.Property("AchievementTypeId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("varchar(2000)"); + + b.Property("WorkshopId") + .HasColumnType("binary(16)"); + + b.HasKey("Id"); + + b.HasIndex("AchievementTypeId"); + + b.HasIndex("WorkshopId"); + + b.ToTable("Achievements"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.AchievementTeacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("AchievementId") + .HasColumnType("binary(16)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("Id"); + + b.HasIndex("AchievementId"); + + b.ToTable("AchievementTeachers"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.AchievementType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.HasKey("Id"); + + b.ToTable("AchievementTypes"); + + b.HasData( + new + { + Id = 1L, + Title = "Переможці міжнародних та всеукраїнських спортивних змагань (індивідуальних та командних)" + }, + new + { + Id = 2L, + Title = "Призери та учасники міжнародних, всеукраїнських та призери регіональних конкурсів і виставок наукових, технічних, дослідницьких, інноваційних, ІТ проектів" + }, + new + { + Id = 3L, + Title = "Реципієнти міжнародних грантів" + }, + new + { + Id = 4L, + Title = "Призери міжнародних культурних конкурсів та фестивалів" + }, + new + { + Id = 5L, + Title = "Соціально активні категорії учнів" + }, + new + { + Id = 6L, + Title = "Цифрові інструменти Google для закладів вищої та фахової передвищої освіти" + }, + new + { + Id = 7L, + Title = "Переможці та учасники олімпіад міжнародного та всеукраїнського рівнів" + }); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Address", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("BuildingNumber") + .IsRequired() + .HasMaxLength(15) + .HasColumnType("varchar(15)"); + + b.Property("City") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("District") + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("Latitude") + .HasColumnType("double"); + + b.Property("Longitude") + .HasColumnType("double"); + + b.Property("Region") + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("Street") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.HasKey("Id"); + + b.ToTable("Addresses"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Application", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("ApprovedTime") + .HasColumnType("datetime(6)"); + + b.Property("ChildId") + .HasColumnType("binary(16)"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)"); + + b.Property("IsBlocked") + .HasColumnType("tinyint(1)"); + + b.Property("ParentId") + .HasColumnType("binary(16)"); + + b.Property("RejectionMessage") + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("Status") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasDefaultValue(1); + + b.Property("WorkshopId") + .HasColumnType("binary(16)"); + + b.HasKey("Id"); + + b.HasIndex("ChildId"); + + b.HasIndex("ParentId"); + + b.HasIndex("WorkshopId"); + + b.ToTable("Applications"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.BlockedProviderParent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("DateTimeFrom") + .HasColumnType("datetime(6)"); + + b.Property("DateTimeTo") + .HasColumnType("datetime(6)"); + + b.Property("ParentId") + .HasColumnType("binary(16)"); + + b.Property("ProviderId") + .HasColumnType("binary(16)"); + + b.Property("Reason") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("UserIdBlock") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UserIdUnblock") + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.HasIndex("ProviderId"); + + b.ToTable("BlockedProviderParents"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.ChatWorkshop.ChatMessageWorkshop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("ChatRoomId") + .HasColumnType("binary(16)"); + + b.Property("CreatedDateTime") + .HasColumnType("datetime(6)"); + + b.Property("ReadDateTime") + .HasColumnType("datetime(6)"); + + b.Property("SenderRoleIsProvider") + .HasColumnType("tinyint(1)"); + + b.Property("Text") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.HasKey("Id"); + + b.HasIndex("ChatRoomId"); + + b.ToTable("ChatMessageWorkshops"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.ChatWorkshop.ChatRoomWorkshop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("IsBlocked") + .HasColumnType("tinyint(1)"); + + b.Property("ParentId") + .HasColumnType("binary(16)"); + + b.Property("WorkshopId") + .HasColumnType("binary(16)"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.HasIndex("WorkshopId"); + + b.ToTable("ChatRoomWorkshops"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Child", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("DateOfBirth") + .HasColumnType("date"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("Gender") + .ValueGeneratedOnAdd() + .HasColumnType("int") + .HasDefaultValue(0); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("MiddleName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("ParentId") + .HasColumnType("binary(16)"); + + b.Property("PlaceOfStudy") + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("Children"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.ChildSocialGroup", b => + { + b.Property("ChildId") + .HasColumnType("binary(16)"); + + b.Property("SocialGroupId") + .HasColumnType("bigint"); + + b.HasKey("ChildId", "SocialGroupId"); + + b.HasIndex("SocialGroupId"); + + b.ToTable("ChildrenSocialGroups"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.City", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("District") + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("GeoHash") + .HasColumnType("bigint unsigned"); + + b.Property("Latitude") + .HasColumnType("double"); + + b.Property("Longitude") + .HasColumnType("double"); + + b.Property("Name") + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("Region") + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.HasKey("Id"); + + b.ToTable("Cities"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Class", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("DepartmentId") + .HasColumnType("bigint"); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("varchar(150)"); + + b.HasKey("Id"); + + b.HasIndex("DepartmentId"); + + b.ToTable("Classes"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.CompanyInformation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("Title") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("CompanyInformation"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.CompanyInformationItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("CompanyInformationId") + .HasColumnType("binary(16)"); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("varchar(2000)"); + + b.Property("SectionName") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.HasKey("Id"); + + b.HasIndex("CompanyInformationId"); + + b.ToTable("CompanyInformationItems"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.DateTimeRange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("EndTime") + .HasColumnType("time(6)"); + + b.Property("StartTime") + .HasColumnType("time(6)"); + + b.Property("Workdays") + .HasColumnType("tinyint unsigned"); + + b.Property("WorkshopId") + .HasColumnType("binary(16)"); + + b.HasKey("Id"); + + b.HasIndex("WorkshopId"); + + b.ToTable("DateTimeRanges"); + + b.HasCheckConstraint("CK_DateTimeRanges_EndTimeIsAfterStartTime", "EndTime >= StartTime"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Department", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("DirectionId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(150) + .HasColumnType("varchar(150)"); + + b.HasKey("Id"); + + b.HasIndex("DirectionId"); + + b.ToTable("Departments"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Direction", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Directions"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.ElasticsearchSyncRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("Entity") + .HasColumnType("int"); + + b.Property("Operation") + .HasColumnType("int"); + + b.Property("OperationDate") + .HasColumnType("datetime(6)"); + + b.Property("RecordId") + .HasColumnType("binary(16)"); + + b.HasKey("Id"); + + b.ToTable("ElasticsearchSyncRecords"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Favorite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("WorkshopId") + .HasColumnType("binary(16)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.HasIndex("WorkshopId"); + + b.ToTable("Favorites"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Images.Image", b => + { + b.Property("EntityId") + .HasColumnType("binary(16)"); + + b.Property("ExternalStorageId") + .HasColumnType("varchar(255)"); + + b.HasKey("EntityId", "ExternalStorageId"); + + b.ToTable("ProviderImages"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Images.Image", b => + { + b.Property("EntityId") + .HasColumnType("binary(16)"); + + b.Property("ExternalStorageId") + .HasColumnType("varchar(255)"); + + b.HasKey("EntityId", "ExternalStorageId"); + + b.ToTable("WorkshopImages"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.InstitutionStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("Id"); + + b.ToTable("InstitutionStatuses"); + + b.HasData( + new + { + Id = 1L, + Name = "Працює" + }, + new + { + Id = 2L, + Name = "Перебуває в стані реорганізації" + }, + new + { + Id = 3L, + Name = "Має намір на реорганізацію" + }); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Notification", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("Action") + .HasColumnType("int"); + + b.Property("CreatedDateTime") + .HasColumnType("datetime(6)"); + + b.Property("Data") + .HasColumnType("longtext"); + + b.Property("GroupedData") + .HasColumnType("longtext"); + + b.Property("ObjectId") + .HasColumnType("binary(16)"); + + b.Property("ReadDateTime") + .HasColumnType("datetime(6)"); + + b.Property("Type") + .HasColumnType("int"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Notifications"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Parent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Parents"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.PermissionsForRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Description") + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.Property("PackedPermissions") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("RoleName") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("varchar(20)"); + + b.HasKey("Id"); + + b.ToTable("PermissionsForRoles"); + + b.HasData( + new + { + Id = 1L, + Description = "admin permissions", + PackedPermissions = "de\n \r  !()+4325>== + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("ActualAddressId") + .HasColumnType("bigint"); + + b.Property("CoverImageId") + .HasColumnType("longtext"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .IsUnicode(true) + .HasColumnType("varchar(500)"); + + b.Property("Director") + .HasMaxLength(50) + .IsUnicode(true) + .HasColumnType("varchar(50)"); + + b.Property("DirectorDateOfBirth") + .HasColumnType("Date"); + + b.Property("EdrpouIpn") + .HasMaxLength(12) + .HasColumnType("bigint"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("Facebook") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("Founder") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("FullTitle") + .IsRequired() + .HasMaxLength(60) + .IsUnicode(true) + .HasColumnType("varchar(60)"); + + b.Property("Instagram") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("InstitutionId") + .HasColumnType("binary(16)"); + + b.Property("InstitutionStatusId") + .HasColumnType("bigint"); + + b.Property("InstitutionType") + .HasColumnType("int"); + + b.Property("LegalAddressId") + .HasColumnType("bigint"); + + b.Property("Ownership") + .HasColumnType("int"); + + b.Property("PhoneNumber") + .HasMaxLength(15) + .HasColumnType("varchar(15)"); + + b.Property("ShortTitle") + .IsRequired() + .HasMaxLength(60) + .IsUnicode(true) + .HasColumnType("varchar(60)"); + + b.Property("Status") + .HasColumnType("tinyint(1)"); + + b.Property("Type") + .HasColumnType("int"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Website") + .HasMaxLength(256) + .IsUnicode(true) + .HasColumnType("varchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("ActualAddressId"); + + b.HasIndex("InstitutionId"); + + b.HasIndex("InstitutionStatusId"); + + b.HasIndex("LegalAddressId"); + + b.HasIndex("UserId"); + + b.ToTable("Providers"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.ProviderAdmin", b => + { + b.Property("UserId") + .HasColumnType("varchar(255)"); + + b.Property("IsDeputy") + .HasColumnType("tinyint(1)"); + + b.Property("ProviderId") + .HasColumnType("binary(16)"); + + b.HasKey("UserId"); + + b.HasIndex("ProviderId"); + + b.ToTable("ProviderAdmins"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.ProviderSectionItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("Description") + .HasMaxLength(2000) + .HasColumnType("varchar(2000)"); + + b.Property("Name") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("ProviderId") + .HasColumnType("binary(16)"); + + b.HasKey("Id"); + + b.HasIndex("ProviderId"); + + b.ToTable("ProviderSectionItems"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Rating", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("CreationTime") + .HasColumnType("datetime(6)"); + + b.Property("EntityId") + .HasColumnType("binary(16)"); + + b.Property("ParentId") + .HasColumnType("binary(16)"); + + b.Property("Rate") + .HasColumnType("int"); + + b.Property("Type") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("Ratings"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.SocialGroup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Name") + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("Id"); + + b.ToTable("SocialGroups"); + + b.HasData( + new + { + Id = 1L, + Name = "Діти із багатодітних сімей" + }, + new + { + Id = 2L, + Name = "Діти із малозабезпечених сімей" + }, + new + { + Id = 3L, + Name = "Діти з інвалідністю" + }, + new + { + Id = 4L, + Name = "Діти-сироти" + }, + new + { + Id = 5L, + Name = "Діти, позбавлені батьківського піклування" + }); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.SubordinationStructure.Institution", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("NumberOfHierarchyLevels") + .HasColumnType("int"); + + b.Property("Title") + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Institutions"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.SubordinationStructure.InstitutionFieldDescription", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("HierarchyLevel") + .HasColumnType("int"); + + b.Property("InstitutionId") + .HasColumnType("binary(16)"); + + b.Property("Title") + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("Id"); + + b.HasIndex("InstitutionId"); + + b.ToTable("InstitutionFieldDescriptions"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.SubordinationStructure.InstitutionHierarchy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("HierarchyLevel") + .HasColumnType("int"); + + b.Property("InstitutionId") + .HasColumnType("binary(16)"); + + b.Property("ParentId") + .HasColumnType("binary(16)"); + + b.Property("Title") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.HasKey("Id"); + + b.HasIndex("InstitutionId"); + + b.HasIndex("ParentId"); + + b.ToTable("InstitutionHierarchies"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Teacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("CoverImageId") + .HasColumnType("longtext"); + + b.Property("DateOfBirth") + .HasColumnType("date"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("varchar(300)"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("MiddleName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("WorkshopId") + .HasColumnType("binary(16)"); + + b.HasKey("Id"); + + b.HasIndex("WorkshopId"); + + b.ToTable("Teachers"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.User", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("longtext"); + + b.Property("CreatingTime") + .HasColumnType("datetime(6)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("tinyint(1)"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("IsBlocked") + .HasColumnType("tinyint(1)"); + + b.Property("IsDerived") + .HasColumnType("tinyint(1)"); + + b.Property("IsRegistered") + .HasColumnType("tinyint(1)"); + + b.Property("LastLogin") + .HasColumnType("datetime(6)"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("LockoutEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("LockoutEnd") + .HasColumnType("datetime(6)"); + + b.Property("MiddleName") + .HasMaxLength(30) + .HasColumnType("varchar(30)"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("PasswordHash") + .HasMaxLength(84) + .IsUnicode(false) + .HasColumnType("char(84)") + .IsFixedLength(true); + + b.Property("PhoneNumber") + .HasMaxLength(15) + .IsUnicode(false) + .HasColumnType("varchar(15)") + .IsFixedLength(false); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("tinyint(1)"); + + b.Property("Role") + .HasMaxLength(50) + .HasColumnType("varchar(50)"); + + b.Property("SecurityStamp") + .IsRequired() + .HasMaxLength(36) + .IsUnicode(false) + .HasColumnType("varchar(36)") + .IsFixedLength(false); + + b.Property("TwoFactorEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Workshop", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("AddressId") + .HasColumnType("bigint"); + + b.Property("ClassId") + .HasColumnType("bigint"); + + b.Property("CoverImageId") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("DepartmentId") + .HasColumnType("bigint"); + + b.Property("Description") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("varchar(500)"); + + b.Property("DirectionId") + .HasColumnType("bigint"); + + b.Property("DisabilityOptionsDesc") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("Facebook") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("Instagram") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("InstitutionHierarchyId") + .HasColumnType("binary(16)"); + + b.Property("IsPerMonth") + .HasColumnType("tinyint(1)"); + + b.Property("Keywords") + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.Property("MaxAge") + .HasColumnType("int"); + + b.Property("MinAge") + .HasColumnType("int"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(15) + .HasColumnType("varchar(15)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.Property("ProviderId") + .HasColumnType("binary(16)"); + + b.Property("ProviderOwnership") + .HasColumnType("int"); + + b.Property("ProviderTitle") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("varchar(60)"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("varchar(60)"); + + b.Property("Website") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("WithDisabilityOptions") + .HasColumnType("tinyint(1)"); + + b.HasKey("Id"); + + b.HasIndex("AddressId"); + + b.HasIndex("ClassId"); + + b.HasIndex("DirectionId"); + + b.HasIndex("InstitutionHierarchyId"); + + b.HasIndex("ProviderId"); + + b.ToTable("Workshops"); + }); + + modelBuilder.Entity("ProviderAdminWorkshop", b => + { + b.Property("ManagedWorkshopsId") + .HasColumnType("binary(16)"); + + b.Property("ProviderAdminsUserId") + .HasColumnType("varchar(255)"); + + b.HasKey("ManagedWorkshopsId", "ProviderAdminsUserId"); + + b.HasIndex("ProviderAdminsUserId"); + + b.ToTable("ProviderAdminWorkshop"); + }); + + modelBuilder.Entity("AchievementChild", b => + { + b.HasOne("OutOfSchool.Services.Models.Achievement", null) + .WithMany() + .HasForeignKey("AchievementsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Child", null) + .WithMany() + .HasForeignKey("ChildrenId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DirectionInstitutionHierarchy", b => + { + b.HasOne("OutOfSchool.Services.Models.Direction", null) + .WithMany() + .HasForeignKey("DirectionsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.SubordinationStructure.InstitutionHierarchy", null) + .WithMany() + .HasForeignKey("InstitutionHierarchiesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("OutOfSchool.Services.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("OutOfSchool.Services.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("OutOfSchool.Services.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Achievement", b => + { + b.HasOne("OutOfSchool.Services.Models.AchievementType", "AchievementType") + .WithMany() + .HasForeignKey("AchievementTypeId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Workshop", "Workshop") + .WithMany() + .HasForeignKey("WorkshopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("AchievementType"); + + b.Navigation("Workshop"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.AchievementTeacher", b => + { + b.HasOne("OutOfSchool.Services.Models.Achievement", "Achievement") + .WithMany("Teachers") + .HasForeignKey("AchievementId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Achievement"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Application", b => + { + b.HasOne("OutOfSchool.Services.Models.Child", "Child") + .WithMany() + .HasForeignKey("ChildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Parent", "Parent") + .WithMany() + .HasForeignKey("ParentId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Workshop", "Workshop") + .WithMany("Applications") + .HasForeignKey("WorkshopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Child"); + + b.Navigation("Parent"); + + b.Navigation("Workshop"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.BlockedProviderParent", b => + { + b.HasOne("OutOfSchool.Services.Models.Parent", "Parent") + .WithMany() + .HasForeignKey("ParentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Provider", "Provider") + .WithMany() + .HasForeignKey("ProviderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Parent"); + + b.Navigation("Provider"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.ChatWorkshop.ChatMessageWorkshop", b => + { + b.HasOne("OutOfSchool.Services.Models.ChatWorkshop.ChatRoomWorkshop", "ChatRoom") + .WithMany("ChatMessages") + .HasForeignKey("ChatRoomId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ChatRoom"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.ChatWorkshop.ChatRoomWorkshop", b => + { + b.HasOne("OutOfSchool.Services.Models.Parent", "Parent") + .WithMany("ChatRooms") + .HasForeignKey("ParentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Workshop", "Workshop") + .WithMany("ChatRooms") + .HasForeignKey("WorkshopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Parent"); + + b.Navigation("Workshop"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Child", b => + { + b.HasOne("OutOfSchool.Services.Models.Parent", "Parent") + .WithMany("Children") + .HasForeignKey("ParentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.ChildSocialGroup", b => + { + b.HasOne("OutOfSchool.Services.Models.Child", "Child") + .WithMany("ChildSocialGroups") + .HasForeignKey("ChildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.SocialGroup", "SocialGroup") + .WithMany("ChildSocialGroups") + .HasForeignKey("SocialGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Child"); + + b.Navigation("SocialGroup"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Class", b => + { + b.HasOne("OutOfSchool.Services.Models.Department", "Department") + .WithMany("Classes") + .HasForeignKey("DepartmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Department"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.CompanyInformationItem", b => + { + b.HasOne("OutOfSchool.Services.Models.CompanyInformation", "CompanyInformation") + .WithMany("CompanyInformationItems") + .HasForeignKey("CompanyInformationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CompanyInformation"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.DateTimeRange", b => + { + b.HasOne("OutOfSchool.Services.Models.Workshop", null) + .WithMany("DateTimeRanges") + .HasForeignKey("WorkshopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Department", b => + { + b.HasOne("OutOfSchool.Services.Models.Direction", "Direction") + .WithMany("Departments") + .HasForeignKey("DirectionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Direction"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Favorite", b => + { + b.HasOne("OutOfSchool.Services.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Workshop", "Workshop") + .WithMany() + .HasForeignKey("WorkshopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + + b.Navigation("Workshop"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Images.Image", b => + { + b.HasOne("OutOfSchool.Services.Models.Provider", "Entity") + .WithMany("Images") + .HasForeignKey("EntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Entity"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Images.Image", b => + { + b.HasOne("OutOfSchool.Services.Models.Workshop", "Entity") + .WithMany("Images") + .HasForeignKey("EntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Entity"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Parent", b => + { + b.HasOne("OutOfSchool.Services.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Provider", b => + { + b.HasOne("OutOfSchool.Services.Models.Address", "ActualAddress") + .WithMany() + .HasForeignKey("ActualAddressId"); + + b.HasOne("OutOfSchool.Services.Models.SubordinationStructure.Institution", "Institution") + .WithMany() + .HasForeignKey("InstitutionId"); + + b.HasOne("OutOfSchool.Services.Models.InstitutionStatus", "InstitutionStatus") + .WithMany("Providers") + .HasForeignKey("InstitutionStatusId"); + + b.HasOne("OutOfSchool.Services.Models.Address", "LegalAddress") + .WithMany() + .HasForeignKey("LegalAddressId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ActualAddress"); + + b.Navigation("Institution"); + + b.Navigation("InstitutionStatus"); + + b.Navigation("LegalAddress"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.ProviderAdmin", b => + { + b.HasOne("OutOfSchool.Services.Models.Provider", "Provider") + .WithMany("ProviderAdmins") + .HasForeignKey("ProviderId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.Navigation("Provider"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.ProviderSectionItem", b => + { + b.HasOne("OutOfSchool.Services.Models.Provider", "Provider") + .WithMany("ProviderSectionItems") + .HasForeignKey("ProviderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Provider"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Rating", b => + { + b.HasOne("OutOfSchool.Services.Models.Parent", "Parent") + .WithMany() + .HasForeignKey("ParentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.SubordinationStructure.InstitutionFieldDescription", b => + { + b.HasOne("OutOfSchool.Services.Models.SubordinationStructure.Institution", "Institution") + .WithMany() + .HasForeignKey("InstitutionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Institution"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.SubordinationStructure.InstitutionHierarchy", b => + { + b.HasOne("OutOfSchool.Services.Models.SubordinationStructure.Institution", "Institution") + .WithMany() + .HasForeignKey("InstitutionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.SubordinationStructure.InstitutionHierarchy", "Parent") + .WithMany() + .HasForeignKey("ParentId"); + + b.Navigation("Institution"); + + b.Navigation("Parent"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Teacher", b => + { + b.HasOne("OutOfSchool.Services.Models.Workshop", "Workshop") + .WithMany("Teachers") + .HasForeignKey("WorkshopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Workshop"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Workshop", b => + { + b.HasOne("OutOfSchool.Services.Models.Address", "Address") + .WithMany() + .HasForeignKey("AddressId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Class", "Class") + .WithMany() + .HasForeignKey("ClassId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Direction", "Direction") + .WithMany() + .HasForeignKey("DirectionId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.SubordinationStructure.InstitutionHierarchy", "InstitutionHierarchy") + .WithMany() + .HasForeignKey("InstitutionHierarchyId"); + + b.HasOne("OutOfSchool.Services.Models.Provider", "Provider") + .WithMany("Workshops") + .HasForeignKey("ProviderId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.Navigation("Address"); + + b.Navigation("Class"); + + b.Navigation("Direction"); + + b.Navigation("InstitutionHierarchy"); + + b.Navigation("Provider"); + }); + + modelBuilder.Entity("ProviderAdminWorkshop", b => + { + b.HasOne("OutOfSchool.Services.Models.Workshop", null) + .WithMany() + .HasForeignKey("ManagedWorkshopsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.ProviderAdmin", null) + .WithMany() + .HasForeignKey("ProviderAdminsUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Achievement", b => + { + b.Navigation("Teachers"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.ChatWorkshop.ChatRoomWorkshop", b => + { + b.Navigation("ChatMessages"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Child", b => + { + b.Navigation("ChildSocialGroups"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.CompanyInformation", b => + { + b.Navigation("CompanyInformationItems"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Department", b => + { + b.Navigation("Classes"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Direction", b => + { + b.Navigation("Departments"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.InstitutionStatus", b => + { + b.Navigation("Providers"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Parent", b => + { + b.Navigation("ChatRooms"); + + b.Navigation("Children"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Provider", b => + { + b.Navigation("Images"); + + b.Navigation("ProviderAdmins"); + + b.Navigation("ProviderSectionItems"); + + b.Navigation("Workshops"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.SocialGroup", b => + { + b.Navigation("ChildSocialGroups"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.Workshop", b => + { + b.Navigation("Applications"); + + b.Navigation("ChatRooms"); + + b.Navigation("DateTimeRanges"); + + b.Navigation("Images"); + + b.Navigation("Teachers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20220621091438_Achievements.cs b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20220621091438_Achievements.cs new file mode 100644 index 0000000000..1a2b72dbd5 --- /dev/null +++ b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/20220621091438_Achievements.cs @@ -0,0 +1,151 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace OutOfSchool.IdentityServer.Data.Migrations.OutOfSchoolMigrations +{ + public partial class Achievements : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AchievementTypes", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + Title = table.Column(type: "varchar(200)", maxLength: 200, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_AchievementTypes", x => x.Id); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Achievements", + columns: table => new + { + Id = table.Column(type: "binary(16)", nullable: false), + Title = table.Column(type: "varchar(2000)", maxLength: 2000, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + AchievementDate = table.Column(type: "date", nullable: false), + WorkshopId = table.Column(type: "binary(16)", nullable: false), + AchievementTypeId = table.Column(type: "bigint", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Achievements", x => x.Id); + table.ForeignKey( + name: "FK_Achievements_AchievementTypes_AchievementTypeId", + column: x => x.AchievementTypeId, + principalTable: "AchievementTypes", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Achievements_Workshops_WorkshopId", + column: x => x.WorkshopId, + principalTable: "Workshops", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "AchievementChild", + columns: table => new + { + AchievementsId = table.Column(type: "binary(16)", nullable: false), + ChildrenId = table.Column(type: "binary(16)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AchievementChild", x => new { x.AchievementsId, x.ChildrenId }); + table.ForeignKey( + name: "FK_AchievementChild_Achievements_AchievementsId", + column: x => x.AchievementsId, + principalTable: "Achievements", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AchievementChild_Children_ChildrenId", + column: x => x.ChildrenId, + principalTable: "Children", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "AchievementTeachers", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + AchievementId = table.Column(type: "binary(16)", nullable: false), + Title = table.Column(type: "varchar(100)", maxLength: 100, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_AchievementTeachers", x => x.Id); + table.ForeignKey( + name: "FK_AchievementTeachers_Achievements_AchievementId", + column: x => x.AchievementId, + principalTable: "Achievements", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.InsertData( + table: "AchievementTypes", + columns: new[] { "Id", "Title" }, + values: new object[,] + { + { 1L, "Переможці міжнародних та всеукраїнських спортивних змагань (індивідуальних та командних)" }, + { 2L, "Призери та учасники міжнародних, всеукраїнських та призери регіональних конкурсів і виставок наукових, технічних, дослідницьких, інноваційних, ІТ проектів" }, + { 3L, "Реципієнти міжнародних грантів" }, + { 4L, "Призери міжнародних культурних конкурсів та фестивалів" }, + { 5L, "Соціально активні категорії учнів" }, + { 6L, "Цифрові інструменти Google для закладів вищої та фахової передвищої освіти" }, + { 7L, "Переможці та учасники олімпіад міжнародного та всеукраїнського рівнів" } + }); + + migrationBuilder.CreateIndex( + name: "IX_AchievementChild_ChildrenId", + table: "AchievementChild", + column: "ChildrenId"); + + migrationBuilder.CreateIndex( + name: "IX_Achievements_AchievementTypeId", + table: "Achievements", + column: "AchievementTypeId"); + + migrationBuilder.CreateIndex( + name: "IX_Achievements_WorkshopId", + table: "Achievements", + column: "WorkshopId"); + + migrationBuilder.CreateIndex( + name: "IX_AchievementTeachers_AchievementId", + table: "AchievementTeachers", + column: "AchievementId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AchievementChild"); + + migrationBuilder.DropTable( + name: "AchievementTeachers"); + + migrationBuilder.DropTable( + name: "Achievements"); + + migrationBuilder.DropTable( + name: "AchievementTypes"); + } + } +} diff --git a/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/OutOfSchoolDbContextModelSnapshot.cs b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/OutOfSchoolDbContextModelSnapshot.cs index 4867561f82..11b609275e 100644 --- a/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/OutOfSchoolDbContextModelSnapshot.cs +++ b/OutOfSchool/OutOfSchool.IdentityServer/Data/Migrations/OutOfSchoolMigrations/OutOfSchoolDbContextModelSnapshot.cs @@ -17,6 +17,21 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasAnnotation("Relational:MaxIdentifierLength", 64) .HasAnnotation("ProductVersion", "5.0.11"); + modelBuilder.Entity("AchievementChild", b => + { + b.Property("AchievementsId") + .HasColumnType("binary(16)"); + + b.Property("ChildrenId") + .HasColumnType("binary(16)"); + + b.HasKey("AchievementsId", "ChildrenId"); + + b.HasIndex("ChildrenId"); + + b.ToTable("AchievementChild"); + }); + modelBuilder.Entity("DirectionInstitutionHierarchy", b => { b.Property("DirectionsId") @@ -177,6 +192,109 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("AspNetUserTokens"); }); + modelBuilder.Entity("OutOfSchool.Services.Models.Achievement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("binary(16)"); + + b.Property("AchievementDate") + .HasColumnType("date"); + + b.Property("AchievementTypeId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(2000) + .HasColumnType("varchar(2000)"); + + b.Property("WorkshopId") + .HasColumnType("binary(16)"); + + b.HasKey("Id"); + + b.HasIndex("AchievementTypeId"); + + b.HasIndex("WorkshopId"); + + b.ToTable("Achievements"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.AchievementTeacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("AchievementId") + .HasColumnType("binary(16)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("varchar(100)"); + + b.HasKey("Id"); + + b.HasIndex("AchievementId"); + + b.ToTable("AchievementTeachers"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.AchievementType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("varchar(200)"); + + b.HasKey("Id"); + + b.ToTable("AchievementTypes"); + + b.HasData( + new + { + Id = 1L, + Title = "Переможці міжнародних та всеукраїнських спортивних змагань (індивідуальних та командних)" + }, + new + { + Id = 2L, + Title = "Призери та учасники міжнародних, всеукраїнських та призери регіональних конкурсів і виставок наукових, технічних, дослідницьких, інноваційних, ІТ проектів" + }, + new + { + Id = 3L, + Title = "Реципієнти міжнародних грантів" + }, + new + { + Id = 4L, + Title = "Призери міжнародних культурних конкурсів та фестивалів" + }, + new + { + Id = 5L, + Title = "Соціально активні категорії учнів" + }, + new + { + Id = 6L, + Title = "Цифрові інструменти Google для закладів вищої та фахової передвищої освіти" + }, + new + { + Id = 7L, + Title = "Переможці та учасники олімпіад міжнародного та всеукраїнського рівнів" + }); + }); + modelBuilder.Entity("OutOfSchool.Services.Models.Address", b => { b.Property("Id") @@ -1505,6 +1623,21 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("ProviderAdminWorkshop"); }); + modelBuilder.Entity("AchievementChild", b => + { + b.HasOne("OutOfSchool.Services.Models.Achievement", null) + .WithMany() + .HasForeignKey("AchievementsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Child", null) + .WithMany() + .HasForeignKey("ChildrenId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("DirectionInstitutionHierarchy", b => { b.HasOne("OutOfSchool.Services.Models.Direction", null) @@ -1571,6 +1704,36 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired(); }); + modelBuilder.Entity("OutOfSchool.Services.Models.Achievement", b => + { + b.HasOne("OutOfSchool.Services.Models.AchievementType", "AchievementType") + .WithMany() + .HasForeignKey("AchievementTypeId") + .OnDelete(DeleteBehavior.NoAction) + .IsRequired(); + + b.HasOne("OutOfSchool.Services.Models.Workshop", "Workshop") + .WithMany() + .HasForeignKey("WorkshopId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("AchievementType"); + + b.Navigation("Workshop"); + }); + + modelBuilder.Entity("OutOfSchool.Services.Models.AchievementTeacher", b => + { + b.HasOne("OutOfSchool.Services.Models.Achievement", "Achievement") + .WithMany("Teachers") + .HasForeignKey("AchievementId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Achievement"); + }); + modelBuilder.Entity("OutOfSchool.Services.Models.Application", b => { b.HasOne("OutOfSchool.Services.Models.Child", "Child") @@ -1998,6 +2161,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired(); }); + modelBuilder.Entity("OutOfSchool.Services.Models.Achievement", b => + { + b.Navigation("Teachers"); + }); + modelBuilder.Entity("OutOfSchool.Services.Models.ChatWorkshop.ChatRoomWorkshop", b => { b.Navigation("ChatMessages"); diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/AchievementController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/AchievementController.cs new file mode 100644 index 0000000000..0685205618 --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/AchievementController.cs @@ -0,0 +1,176 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Mime; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Localization; +using OutOfSchool.Common.PermissionsModule; +using OutOfSchool.WebApi.Extensions; +using OutOfSchool.WebApi.Models; +using OutOfSchool.WebApi.Models.Achievement; +using OutOfSchool.WebApi.Services; + +namespace OutOfSchool.WebApi.Controllers.V1 +{ + /// + /// Controller with CRUD operations for Achievement entity. + /// + [ApiController] + [ApiVersion("1.0")] + [Route("api/v{version:apiVersion}/[controller]/[action]")] + public class AchievementController : ControllerBase + { + private readonly IAchievementService achievementService; + private readonly IStringLocalizer localizer; + + /// + /// Initializes a new instance of the class. + /// + /// Service for Achievement entity. + /// Localizer. + public AchievementController(IAchievementService service, IStringLocalizer localizer) + { + this.localizer = localizer; + this.achievementService = service; + } + + /// + /// To recieve the Achievement with the defined id. + /// + /// Key of the Achievement in the table. + /// . + /// The entity was found by given Id. + /// If any server error occures. For example: Id was wrong. + [AllowAnonymous] + [HttpGet("{id}")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(AchievementDto))] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetById(Guid id) + { + return Ok(await achievementService.GetById(id).ConfigureAwait(false)); + } + + /// + /// To recieve the Achievement list by Workshop id. + /// + /// Key of the Workshop in the table. + /// List of achievements. + /// The entity was found by given Id. + /// If any server error occures. For example: Id was wrong. + [AllowAnonymous] + [HttpGet("{workshopId}")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable))] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task GetByWorkshopId(Guid workshopId) + { + var achievements = await achievementService.GetByWorkshopId(workshopId).ConfigureAwait(false); + + if (!achievements.Any()) + { + return NoContent(); + } + + return Ok(achievements); + } + + /// + /// To create a new Achievement and add it to the DB. + /// + /// AchievementCreateDto object that will be added. + /// Achievement that was created. + /// Achievement was successfully created. + /// Model is invalid. + /// If the user is not authorized. + /// If the user has no rights to use this method. + /// If any server error occures. + [HttpPost] + [Consumes(MediaTypeNames.Application.Json)] + [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Create(AchievementCreateDTO achievementDto) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + try + { + achievementDto.Id = default; + + var achievement = await achievementService.Create(achievementDto).ConfigureAwait(false); + + return CreatedAtAction( + nameof(GetById), + new { id = achievement.Id, }, + achievement); + } + catch (ArgumentException ex) + { + return BadRequest(ex.Message); + } + } + + /// + /// To update Achievement entity that already exists. + /// + /// AchievementCreateDTO object with new properties. + /// Achievement that was updated. + /// Achievement was successfully updated. + /// Model is invalid. + /// If the user is not authorized. + /// If the user has no rights to use this method. + /// If any server error occures. + [HttpPut] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(AchievementDto))] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Update(AchievementCreateDTO achievementDto) + { + if (!ModelState.IsValid) + { + return BadRequest(ModelState); + } + + return Ok(await achievementService.Update(achievementDto).ConfigureAwait(false)); + } + + /// + /// Delete the Achievement entity from DB. + /// + /// The key of the Achievement in table. + /// Status Code. + /// Achievement was successfully deleted. + /// If some workshops assosiated with this Achievement. + /// If the user is not authorized. + /// If the user has no rights to use this method. + /// If any server error occures. + [HttpDelete("{id}")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task Delete(Guid id) + { + try + { + await achievementService.Delete(id).ConfigureAwait(false); + return NoContent(); + } + + catch (ArgumentException ex) + { + return BadRequest(ex.Message); + } + } + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/Achievement/AchievementCreateDTO.cs b/OutOfSchool/OutOfSchool.WebApi/Models/Achievement/AchievementCreateDTO.cs new file mode 100644 index 0000000000..c3a97e2894 --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Models/Achievement/AchievementCreateDTO.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace OutOfSchool.WebApi.Models.Achievement +{ + public class AchievementCreateDTO + { + public Guid Id { get; set; } + + [Required(ErrorMessage = "Title is required")] + [DataType(DataType.Text)] + [MaxLength(2000)] + [MinLength(1)] + public string Title { get; set; } + + [Required] + [DataType(DataType.Date)] + [Column(TypeName = "date")] + public DateTime AchievementDate { get; set; } = default; + + [Required] + public Guid WorkshopId { get; set; } + + [Required] + public long AchievementTypeId { get; set; } + + public List ChildrenIDs { get; set; } + + public List Teachers { get; set; } + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/Achievement/AchievementDto.cs b/OutOfSchool/OutOfSchool.WebApi/Models/Achievement/AchievementDto.cs new file mode 100644 index 0000000000..08fbaa8165 --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Models/Achievement/AchievementDto.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using OutOfSchool.WebApi.Models.Achievement; + +namespace OutOfSchool.WebApi.Models +{ + public class AchievementDto + { + public Guid Id { get; set; } + + [Required(ErrorMessage = "Title is required")] + [DataType(DataType.Text)] + [MaxLength(2000)] + [MinLength(1)] + public string Title { get; set; } + + [Required] + [DataType(DataType.Date)] + [Column(TypeName = "date")] + public DateTime AchievementDate { get; set; } = default; + + [Required] + public Guid WorkshopId { get; set; } + + [Required] + public long AchievementTypeId { get; set; } + + public List Children { get; set; } + + public List Teachers { get; set; } + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/Achievement/AchievementTeacherDto.cs b/OutOfSchool/OutOfSchool.WebApi/Models/Achievement/AchievementTeacherDto.cs new file mode 100644 index 0000000000..684278c497 --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Models/Achievement/AchievementTeacherDto.cs @@ -0,0 +1,19 @@ +using System; +using System.ComponentModel.DataAnnotations; + +namespace OutOfSchool.WebApi.Models.Achievement +{ + public class AchievementTeacherDto + { + public long Id { get; set; } + + [Required] + public Guid AchievementId { get; set; } + + [Required(ErrorMessage = "Title is required")] + [DataType(DataType.Text)] + [MaxLength(100)] + [MinLength(1)] + public string Title { get; set; } + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/Achievement/AchievementTypeDto.cs b/OutOfSchool/OutOfSchool.WebApi/Models/Achievement/AchievementTypeDto.cs new file mode 100644 index 0000000000..d795e5a8c8 --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Models/Achievement/AchievementTypeDto.cs @@ -0,0 +1,15 @@ +using System.ComponentModel.DataAnnotations; + +namespace OutOfSchool.WebApi.Models +{ + public class AchievementTypeDto + { + public long Id { get; set; } + + [Required(ErrorMessage = "Title is required")] + [DataType(DataType.Text)] + [MaxLength(200)] + [MinLength(1)] + public string Title { get; set; } + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/AchievementService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/AchievementService.cs new file mode 100644 index 0000000000..0b325ec561 --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Services/AchievementService.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using AutoMapper; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Logging; +using OutOfSchool.Services; +using OutOfSchool.Services.Models; +using OutOfSchool.Services.Repository; +using OutOfSchool.WebApi.Common; +using OutOfSchool.WebApi.Extensions; +using OutOfSchool.WebApi.Models; +using OutOfSchool.WebApi.Models.Achievement; +using OutOfSchool.WebApi.Util; + +namespace OutOfSchool.WebApi.Services +{ + public class AchievementService: IAchievementService + { + private readonly IAchievementRepository achievementRepository; + private readonly ILogger logger; + private readonly IStringLocalizer localizer; + private readonly IMapper mapper; + + /// + /// Initializes a new instance of the class. + /// + /// Repository for Achievement entity. + /// Logger. + /// Localizer. + /// Mapper. + public AchievementService( + IAchievementRepository repository, + ILogger logger, + IStringLocalizer localizer, + IMapper mapper, + OutOfSchoolDbContext context) + { + this.localizer = localizer; + this.achievementRepository = repository; + this.logger = logger; + this.mapper = mapper; + } + + /// + public async Task GetById(Guid id) + { + logger.LogInformation($"Getting Achievement by Id started. Looking Id = {id}."); + + var achievement = await achievementRepository.GetById(id).ConfigureAwait(false); + + if (achievement == null) + { + throw new ArgumentOutOfRangeException( + nameof(id), + localizer["The id cannot be greater than number of table entities."]); + } + + logger.LogInformation($"Successfully got a Achievement with Id = {id}."); + + return mapper.Map(achievement); + } + + /// + public async Task> GetByWorkshopId(Guid id) + { + logger.LogInformation("Getting all Achievements by Workshop Id started."); + + var achievements = await achievementRepository.GetByWorkshopId(id).ConfigureAwait(false); + + logger.LogInformation(!achievements.Any() + ? "This Workshop has no achievements." + : $"All {achievements.Count()} records were successfully received"); + + return mapper.Map>(achievements); + } + + /// + public async Task Create(AchievementCreateDTO dto) + { + logger.LogInformation("Achievement creating was started."); + + if (dto is null) + { + logger.LogInformation("Operation failed, dto is null"); + throw new ArgumentException(localizer["dto is null."], nameof(dto)); + } + + var achievement = mapper.Map(dto); + + var newAchievement = await achievementRepository.Create(achievement, dto.ChildrenIDs, dto.Teachers).ConfigureAwait(false); + + logger.LogInformation($"Achievement with Id = {newAchievement?.Id} created successfully."); + + return mapper.Map(newAchievement); + } + + /// + public async Task Update(AchievementCreateDTO dto) + { + logger.LogInformation($"Updating Achievement with Id = {dto?.Id} started."); + + if (dto is null) + { + logger.LogInformation("Operation failed, dto is null"); + throw new ArgumentException(localizer["dto is null."], nameof(dto)); + } + + try + { + var updatedAchievement = await achievementRepository.Update(mapper.Map(dto), dto.ChildrenIDs, dto.Teachers) + .ConfigureAwait(false); + + logger.LogInformation($"Achievement with Id = {updatedAchievement?.Id} updated succesfully."); + + return mapper.Map(updatedAchievement); + } + catch (DbUpdateConcurrencyException) + { + logger.LogError($"Updating failed. Achievement with Id = {dto?.Id} doesn't exist in the system."); + throw; + } + } + + /// + public async Task Delete(Guid id) + { + logger.LogInformation($"Deleting Achievement with Id = {id} started."); + + var achievement = achievementRepository.Get(where: a => a.Id == id); + + if (!achievement.Any()) + { + logger.LogInformation($"Operation failed. Achievement with Id = {id} doesn't exist in the system."); + throw new ArgumentException(localizer[$"Achievement with Id = {id} doesn't exist in the system."]); + } + + var entity = new Achievement { Id = id }; + + try + { + await achievementRepository.Delete(entity).ConfigureAwait(false); + + logger.LogInformation($"Achievement with Id = {id} succesfully deleted."); + } + catch (DbUpdateConcurrencyException) + { + logger.LogError($"Deleting failed. Achievement with Id = {id} doesn't exist in the system."); + throw; + } + } + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/IAchievementService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/IAchievementService.cs new file mode 100644 index 0000000000..399c32dbfa --- /dev/null +++ b/OutOfSchool/OutOfSchool.WebApi/Services/IAchievementService.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using OutOfSchool.Services.Models; +using OutOfSchool.WebApi.Common; +using OutOfSchool.WebApi.Models; +using OutOfSchool.WebApi.Models.Achievement; + +namespace OutOfSchool.WebApi.Services +{ + /// + /// Defines interface for CRUD functionality for Achievement entity. + /// + public interface IAchievementService + { + /// + /// To recieve the Achievement object with define id. + /// + /// Key in the table. + /// A representing the result of the asynchronous operation. + /// The task result contains a that was found. + Task GetById(Guid id); + + /// + /// To recieve all Achievement objects by Workshop id. + /// + /// Workshop Key in the table. + /// List of Achievement objects. + Task> GetByWorkshopId(Guid id); + + /// + /// Add new Achievement to the DB. + /// + /// AchievementCreateDTO element. + /// A representing the result of the asynchronous operation. + /// The task result contains a that was created. + Task Create(AchievementCreateDTO dto); + + /// + /// To Update our object in DB. + /// + /// Achievement with new properties. + /// A representing the result of the asynchronous operation. + /// The task result contains a that was updated. + Task Update(AchievementCreateDTO dto); + + /// + /// To delete the object from DB. + /// + /// Key of the Achievement in table. + /// A representing the result of the asynchronous operation. + Task Delete(Guid id); + } +} diff --git a/OutOfSchool/OutOfSchool.WebApi/Startup.cs b/OutOfSchool/OutOfSchool.WebApi/Startup.cs index 2fd55b2694..9683d1bf24 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Startup.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Startup.cs @@ -289,6 +289,11 @@ public void ConfigureServices(IServiceCollection services) services.AddTransient(); services.AddTransient, EntityRepository>(); + services.AddTransient, EntityRepository>(); + services.AddTransient, EntityRepository>(); + services.AddTransient(); + services.AddTransient(); + // Institution hierarchy services.AddTransient, SensitiveEntityRepository>(); services.AddTransient, SensitiveEntityRepository>(); diff --git a/OutOfSchool/OutOfSchool.WebApi/Util/MappingProfile.cs b/OutOfSchool/OutOfSchool.WebApi/Util/MappingProfile.cs index d3c703442e..8950b0571f 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Util/MappingProfile.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Util/MappingProfile.cs @@ -6,6 +6,7 @@ using OutOfSchool.ElasticsearchData.Models; using OutOfSchool.Services.Models; using OutOfSchool.Services.Models.SubordinationStructure; +using OutOfSchool.WebApi.Models.Achievement; using OutOfSchool.WebApi.Models; using OutOfSchool.WebApi.Models.BlockedProviderParent; using OutOfSchool.WebApi.Models.Changes; @@ -181,6 +182,13 @@ public MappingProfile() CreateMap() .AfterMap((src, dest) => dest.EntityType = "Application"); + CreateMap().ReverseMap(); + + CreateMap().ReverseMap(); + + CreateMap() + .ForMember(dest => dest.Children, opt => opt.Ignore()) + .ForMember(dest => dest.Teachers, opt => opt.Ignore()); } } }