| Task RemoveUser(User user); | Task RemoveUser(User user); | ||||
| Task<ServiceResponseDTO<object>> SendRegistrationLink(InviteDTO invite); | Task<ServiceResponseDTO<object>> SendRegistrationLink(InviteDTO invite); | ||||
| Task<User> GetFirst(); | Task<User> GetFirst(); | ||||
| Task GrantCategoryToUserAsync(GrantUserCategoryRequestDto request); | |||||
| } | } | ||||
| } | } |
| Data = new { Message = "Link has been sent!" } | Data = new { Message = "Link has been sent!" } | ||||
| }; | }; | ||||
| } | } | ||||
| public async Task GrantCategoryToUserAsync(GrantUserCategoryRequestDto request) | |||||
| { | |||||
| for (int i = 0; i < request.CategoriesId.Count; i++) | |||||
| { | |||||
| await _databaseContext.UserCategories.AddAsync(new UserCategories { UserId = request.UserId, CategoryId = request.CategoriesId[i] }); | |||||
| } | |||||
| await _databaseContext.SaveChangesAsync(); | |||||
| } | |||||
| } | } | ||||
| } | } |
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace Diligent.WebAPI.Contracts.DTOs.User | |||||
| { | |||||
| public class GrantUserCategoryRequestDto | |||||
| { | |||||
| public int UserId { get; set; } | |||||
| public List<int>CategoriesId { get; set; } | |||||
| } | |||||
| } |
| public DbSet<FileEntity> Files { get; set; } | public DbSet<FileEntity> Files { get; set; } | ||||
| public DbSet<Category> Categories { get; set; } | public DbSet<Category> Categories { get; set; } | ||||
| public DbSet<Tag> Tags { get; set; } | public DbSet<Tag> Tags { get; set; } | ||||
| public DbSet<UserCategories> UserCategories { get; set; } | |||||
| public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options) { } | public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options) { } |
| public string Name { get; set; } | public string Name { get; set; } | ||||
| public List<FileEntity> Files { get; set; } | public List<FileEntity> Files { get; set; } | ||||
| public List<UserCategories> UserCategories { get; set; } | |||||
| } | } | ||||
| } | } |
| public List<SelectionProcess> Processes { get; set; } = new(); | public List<SelectionProcess> Processes { get; set; } = new(); | ||||
| public string? Position { get; set; } | public string? Position { get; set; } | ||||
| public string? LinkedIn { get; set; } | public string? LinkedIn { get; set; } | ||||
| public List<UserCategories> UserCategories { get; set; } | |||||
| } | } |
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.Linq; | |||||
| using System.Text; | |||||
| using System.Threading.Tasks; | |||||
| namespace Diligent.WebAPI.Data.Entities | |||||
| { | |||||
| public class UserCategories | |||||
| { | |||||
| public int Id { get; set; } | |||||
| public int UserId { get; set; } | |||||
| public int CategoryId { get; set; } | |||||
| } | |||||
| } |
| using Microsoft.EntityFrameworkCore.Migrations; | |||||
| #nullable disable | |||||
| namespace Diligent.WebAPI.Data.Migrations | |||||
| { | |||||
| public partial class UserCategoryManyToMany : Migration | |||||
| { | |||||
| protected override void Up(MigrationBuilder migrationBuilder) | |||||
| { | |||||
| migrationBuilder.CreateTable( | |||||
| name: "UserCategories", | |||||
| columns: table => new | |||||
| { | |||||
| Id = table.Column<int>(type: "int", nullable: false) | |||||
| .Annotation("SqlServer:Identity", "1, 1"), | |||||
| UserId = table.Column<int>(type: "int", nullable: false), | |||||
| CategoryId = table.Column<int>(type: "int", nullable: false) | |||||
| }, | |||||
| constraints: table => | |||||
| { | |||||
| table.PrimaryKey("PK_UserCategories", x => x.Id); | |||||
| table.ForeignKey( | |||||
| name: "FK_UserCategories_AspNetUsers_UserId", | |||||
| column: x => x.UserId, | |||||
| principalTable: "AspNetUsers", | |||||
| principalColumn: "Id", | |||||
| onDelete: ReferentialAction.Cascade); | |||||
| table.ForeignKey( | |||||
| name: "FK_UserCategories_Categories_CategoryId", | |||||
| column: x => x.CategoryId, | |||||
| principalTable: "Categories", | |||||
| principalColumn: "Id", | |||||
| onDelete: ReferentialAction.Cascade); | |||||
| }); | |||||
| migrationBuilder.CreateIndex( | |||||
| name: "IX_UserCategories_CategoryId", | |||||
| table: "UserCategories", | |||||
| column: "CategoryId"); | |||||
| migrationBuilder.CreateIndex( | |||||
| name: "IX_UserCategories_UserId", | |||||
| table: "UserCategories", | |||||
| column: "UserId"); | |||||
| } | |||||
| protected override void Down(MigrationBuilder migrationBuilder) | |||||
| { | |||||
| migrationBuilder.DropTable( | |||||
| name: "UserCategories"); | |||||
| } | |||||
| } | |||||
| } |
| b.ToTable("AspNetUsers", (string)null); | b.ToTable("AspNetUsers", (string)null); | ||||
| }); | }); | ||||
| modelBuilder.Entity("Diligent.WebAPI.Data.Entities.UserCategories", b => | |||||
| { | |||||
| b.Property<int>("Id") | |||||
| .ValueGeneratedOnAdd() | |||||
| .HasColumnType("int"); | |||||
| SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1); | |||||
| b.Property<int>("CategoryId") | |||||
| .HasColumnType("int"); | |||||
| b.Property<int>("UserId") | |||||
| .HasColumnType("int"); | |||||
| b.HasKey("Id"); | |||||
| b.HasIndex("CategoryId"); | |||||
| b.HasIndex("UserId"); | |||||
| b.ToTable("UserCategories"); | |||||
| }); | |||||
| modelBuilder.Entity("Diligent.WebAPI.Data.Entities.WebhookDefinition", b => | modelBuilder.Entity("Diligent.WebAPI.Data.Entities.WebhookDefinition", b => | ||||
| { | { | ||||
| b.Property<long>("Id") | b.Property<long>("Id") | ||||
| b.Navigation("Technology"); | b.Navigation("Technology"); | ||||
| }); | }); | ||||
| modelBuilder.Entity("Diligent.WebAPI.Data.Entities.UserCategories", b => | |||||
| { | |||||
| b.HasOne("Diligent.WebAPI.Data.Entities.Category", null) | |||||
| .WithMany("UserCategories") | |||||
| .HasForeignKey("CategoryId") | |||||
| .OnDelete(DeleteBehavior.Cascade) | |||||
| .IsRequired(); | |||||
| b.HasOne("Diligent.WebAPI.Data.Entities.User", null) | |||||
| .WithMany("UserCategories") | |||||
| .HasForeignKey("UserId") | |||||
| .OnDelete(DeleteBehavior.Cascade) | |||||
| .IsRequired(); | |||||
| }); | |||||
| modelBuilder.Entity("Diligent.WebAPI.Data.Entities.WebhookSubscription", b => | modelBuilder.Entity("Diligent.WebAPI.Data.Entities.WebhookSubscription", b => | ||||
| { | { | ||||
| b.HasOne("Diligent.WebAPI.Data.Entities.WebhookDefinition", "WebhookDefinition") | b.HasOne("Diligent.WebAPI.Data.Entities.WebhookDefinition", "WebhookDefinition") | ||||
| modelBuilder.Entity("Diligent.WebAPI.Data.Entities.Category", b => | modelBuilder.Entity("Diligent.WebAPI.Data.Entities.Category", b => | ||||
| { | { | ||||
| b.Navigation("Files"); | b.Navigation("Files"); | ||||
| b.Navigation("UserCategories"); | |||||
| }); | }); | ||||
| modelBuilder.Entity("Diligent.WebAPI.Data.Entities.SelectionLevel", b => | modelBuilder.Entity("Diligent.WebAPI.Data.Entities.SelectionLevel", b => | ||||
| b.Navigation("Comments"); | b.Navigation("Comments"); | ||||
| b.Navigation("Processes"); | b.Navigation("Processes"); | ||||
| b.Navigation("UserCategories"); | |||||
| }); | }); | ||||
| #pragma warning restore 612, 618 | #pragma warning restore 612, 618 | ||||
| } | } |
| return Ok(response.Data); | return Ok(response.Data); | ||||
| } | } | ||||
| [HttpPost("grant-category")] | |||||
| public async Task<IActionResult> GrantCategoryToUser([FromBody]GrantUserCategoryRequestDto request) | |||||
| { | |||||
| await _userService.GrantCategoryToUserAsync(request); | |||||
| return StatusCode(201); | |||||
| } | |||||
| } | } | ||||
| } | } |