Add Identity configuration, DTOs and Mappers #1

Merged
m.bengashier merged 6 commits from Feat/Identity into main 2025-02-09 08:19:35 +00:00
59 changed files with 6313 additions and 185 deletions
Showing only changes of commit d2a32d35f4 - Show all commits

View File

@@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace survey_beta.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class AnalyticsController : ControllerBase
{
private readonly AnalyticsServices _analyticsServices;
public AnalyticsController(AnalyticsServices analyticsServices)
{
_analyticsServices = analyticsServices;
}
[HttpGet("survey/{surveyId}")]
public IActionResult GetSurveyAnalytics(string surveyId)
{
var analytics = _analyticsServices.GetAggregatedSurveyResponses(surveyId);
if (analytics == null) return NotFound("Survey analytics not found.");
return Ok(analytics);
}
[HttpGet("export/{surveyId}")]
public IActionResult ExportSurveyData(string surveyId)
{
return _analyticsServices.ExportSurveyDataToCsv(surveyId);
}
}
}

View File

@@ -0,0 +1,39 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using survey_beta.DTOs.Response;
namespace survey_beta.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ResponsesController : ControllerBase
{
private readonly ResponsesService _responsesService;
public ResponsesController(ResponsesService responsesService)
{
_responsesService = responsesService;
}
[HttpPost("add")]
public IActionResult AddResponse([FromBody] CreatorResponseDto request)
{
try
{
_responsesService.AddResponse(request);
return Ok("Response added successfully.");
}
catch (Exception ex)
{
return BadRequest(new { message = ex.Message });
}
}
[HttpGet("survey/{surveyId}")]
public IActionResult GetSurveyResponses(string surveyId)
{
var responses = _responsesService.GetSurveyResponses(surveyId);
if (responses == null || responses.Count == 0) return NotFound("No responses found for this survey.");
return Ok(responses);
}
}
}

View File

@@ -1,19 +1,103 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using survey_beta.DataBaseContext;
using survey_beta.DTOs.Default;
using survey_beta.Mappers;
using survey_beta.DTOs.Create;
using survey_beta.DTOs.Response;
using survey_beta.DTOs.Update;
using survey_beta.Models;
using survey_beta.Services;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
namespace survey_beta.Controllers
[Route("api/[controller]")]
[ApiController]
public class SurveyController : ControllerBase
{
[Route("api/Surveys")]
[ApiController]
public class SurveyController : ControllerBase
private readonly SurveyService _surveyService;
private readonly UserManager<User> _userManager;
public SurveyController(SurveyService surveyService, UserManager<User> userManager)
{
_surveyService = surveyService;
_userManager = userManager;
}
[HttpGet("{id}")]
public async Task<IActionResult> GetById(string id)
{
var userId = _userManager.GetUserId(User);
var survey = await _surveyService.GetSurveyByIdAsync(id);
if (survey == null)
{
return NotFound();
}
if (userId != survey.AuthorId)
{
return Forbid();
}
var result = new SurveyResponseDto
{
Id = survey.Id,
Title = survey.Title,
Description = survey.Description,
Category = survey.Category,
ExpirationDate = survey.ExpirationDate,
IsPublished = survey.IsPublished,
};
return Ok(result);
}
[Authorize]
[HttpPost]
public async Task<ActionResult<Survey>> CreateSurvey([FromBody] CreateSurveyDto request)
{
try
{
var survey = await _surveyService.CreateSurveyAsync(request);
return CreatedAtAction(nameof(GetById), new { id = survey.Id }, survey);
}
catch (Exception ex)
{
return BadRequest(new { message = ex.Message });
}
}
[Authorize]
[HttpPut]
public async Task<IActionResult> UpdateSurvey([FromBody] UpdateSurveyDto request)
{
var success = await _surveyService.UpdateSurveyAsync(request);
if (!success) return NotFound(new { message = "Survey not found." });
return NoContent();
}
[Authorize]
[HttpPatch("publish/{id}")]
public async Task<IActionResult> PublishSurvey(string id)
{
var success = await _surveyService.PublishSurveyAsync(id);
if (!success) return NotFound(new { message = "Survey not found." });
return NoContent();
}
[Authorize]
[HttpPatch("unpublish/{id}")]
public async Task<IActionResult> UnpublishSurvey(string id)
{
var success = await _surveyService.UnpublishSurveyAsync(id);
if (!success) return NotFound(new { message = "Survey not found." });
return NoContent();
}
[Authorize]
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteSurvey(string id)
{
var success = await _surveyService.DeleteSurveyAsync(id);
if (!success) return NotFound(new { message = "Survey not found." });
return NoContent();
}
}

View File

@@ -1,11 +1,79 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using survey_beta.DTOs.Create;
using survey_beta.DTOs.Default;
namespace survey_beta.Controllers
[Route("api/[controller]")]
[ApiController]
public class UserController : ControllerBase
{
[Route("api/Users")]
[ApiController]
public class UsersController : ControllerBase
private readonly UsersServices _usersServices;
public UserController(UsersServices usersServices)
{
_usersServices = usersServices;
}
[HttpPost("register")]
public async Task<ActionResult<UserDto>> Register([FromBody] CreateUserDto createUserDto)
{
try
{
var user = await _usersServices.CreateUserAsync(createUserDto);
return Ok(user);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
}
[HttpPost("login")]
public async Task<ActionResult<UserDto>> Login([FromBody] LoginDto loginDto)
{
try
{
var user = await _usersServices.SignInAsync(loginDto);
return Ok(user);
}
catch (Exception ex)
{
return Unauthorized(ex.Message);
}
}
[Authorize]
[HttpGet("{id}")]
public async Task<IActionResult> GetUserById(string id)
{
try
{
var user = await _usersServices.GetUserByIdAsync(id);
return Ok(user);
}
catch (Exception ex)
{
return NotFound(new { message = ex.Message });
}
}
[Authorize]
[HttpGet("by-username/{username}")]
public async Task<IActionResult> GetUserByUsername(string username)
{
try
{
var user = await _usersServices.GetUserByUsernameAsync(username);
return Ok(user);
}
catch (Exception ex)
{
return NotFound(new { message = ex.Message });
}
}
[Authorize]
[HttpGet("All-Users")]
public async Task<IActionResult> GetAllUsers()
{
var users = await _usersServices.GetAllUsersAsync();
return Ok(users);
}
}

View File

@@ -1,9 +1,13 @@
namespace survey_beta.DTOs.Create
using System;
using System.Collections.Generic;
namespace survey_beta.DTOs.Create
{
public class CreateQuestionDto
{
public string Content { get; set; }
public string SurveyId { get; set; } = Guid.NewGuid().ToString();
public string SurveyId { get; set; }
public List<CreateChoiceDto> Choices { get; set; }
}
}

View File

@@ -4,6 +4,7 @@
{
public string IpAddress { get; set; }
public string SurveyId { get; set; }
public List<CreateAnswerDto> Answers { get; set; }
public string Id { get; set; }
public string? Answer { get; set; }
}
}

View File

@@ -1,12 +1,15 @@
namespace survey_beta.DTOs.Create
using System;
using System.Collections.Generic;
namespace survey_beta.DTOs.Create
{
public class CreateSurveyDto
{
public string Id { get; set; } = Guid.NewGuid().ToString();
public string Title { get; set; }
public string Description { get; set; }
public string Category { get; set; }
public DateTime ExpirationDate { get; set; }
public List<CreateQuestionDto> Questions { get; set; }
}
}

View File

@@ -2,7 +2,7 @@
{
public class LoginDto
{
public string UserName { get; set; }
public string Username { get; set; }
public string Password { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace survey_beta.DTOs.Default
{
public class AnswerDto
{
public string Question { get; set; }
public string AnswerText { get; set; }
public string ResponseId { get; set; }
}
}

View File

@@ -1,4 +1,6 @@
namespace survey_beta.DTOs.Default
using System;
namespace survey_beta.DTOs.Default
{
public class ChoiceDto
{

View File

@@ -5,6 +5,8 @@
public string Id { get; set; }
public string IpAddress { get; set; }
public string SurveyId { get; set; }
public List<AnswerDto> Answers { get; set; }
public string Answer { get; set; }
public DateTime CreatedAt { get; set; }
}
}

View File

@@ -0,0 +1,8 @@
namespace survey_beta.DTOs.Default
{
public class SurveyParametersDto
{
public string? AuthorId { get; set; }
public string? Category { get; set; }
}
}

View File

@@ -6,5 +6,6 @@
public string? Email { get; set; }
public string? Username { get; set; }
public string? Fullname { get; set; }
public string Token { get; set; }

remove the authored surveys property from the dto

remove the authored surveys property from the dto
}
}

View File

@@ -0,0 +1,6 @@
namespace survey_beta.DTOs.Default
{
public class UserInfoDto
{
}
}

View File

@@ -0,0 +1,8 @@
namespace survey_beta.DTOs.Response
{
public class AnswerRequest
{
public string Question { get; set; }
public string AnswerText { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace survey_beta.DTOs.Response
{
public class AuthorResponseDto
{
public string Id { get; set; }
public string Fullname { get; set; }
public string Username { get; set; }
}
}

View File

@@ -0,0 +1,10 @@
namespace survey_beta.DTOs.Response
{
public class CreatorResponseDto
{
public string Id { get; set; }
public string IpAddress { get; set; }
public string SurveyId { get; set; }
public List<AnswerRequest> Answers { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace survey_beta.DTOs.Response
{
public class ResponseDto
{
public string Id { get; set; }
public string IpAddress { get; set; }
public string SurveyId { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
namespace survey_beta.DTOs.Response
{
public class SurveyResponseDto
{
public string Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Category { get; set; }
public DateTime? ExpirationDate { get; set; }
public bool IsPublished { get; set; }
}
}

View File

@@ -0,0 +1,9 @@
namespace survey_beta.DTOs.Update
{
public class SurveyAnalytics
{
public string SurveyId { get; set; }
public int TotalResponses { get; set; }
public DateTime CreatedAt { get; set; }
}
}

View File

@@ -0,0 +1,10 @@
namespace survey_beta.DTOs.Update
{
public class SurveyStats
{
public string SurveyId { get; set; }
public int TotalResponses { get; set; }
public Dictionary<string, int> AnswerFrequency { get; set; }
public Dictionary<string, int> QuestionFrequency { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
namespace survey_beta.DTOs.Update
{
public class UpdateSurveyDto
{
public string Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Category { get; set; }
public DateTime? ExpirationDate { get; set; }
public bool IsPublished { get; set; }
}
}

View File

@@ -1,14 +1,11 @@

using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using survey_beta.Models;
namespace survey_beta.DataBaseContext
{
public class AppDbContext : Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityDbContext<User>
public class AppDbContext : IdentityDbContext<User>
{
public override DbSet<User> Users { get; set; }
public DbSet<Survey> Surveys { get; set; }
public DbSet<Question> Questions { get; set; }
public DbSet<Choice> Choices { get; set; }
@@ -18,43 +15,50 @@ namespace survey_beta.DataBaseContext
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<User>()
.Property(u => u.Fullname)
.IsRequired();
modelBuilder.Entity<Survey>()
.HasOne(s => s.Author)
.WithMany(u => u.Surveys)
.HasForeignKey(s => s.AuthorId);
.HasForeignKey(s => s.AuthorId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Question>()
.HasOne(q => q.Survey)
.WithMany(s => s.Questions)
.HasForeignKey(q => q.SurveyId);
.WithMany(s => s.Questions)
.HasForeignKey(q => q.SurveyId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Choice>()
.HasOne(c => c.Question)
.WithMany(q => q.Choices)
.HasForeignKey(c => c.QuestionId);
modelBuilder.Entity<Response>()
.HasOne(r => r.Survey)
.WithMany(s => s.Responses)
.HasForeignKey(r => r.SurveyId);
.HasForeignKey(c => c.QuestionId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Answer>()
.HasOne(a => a.Response)
.WithMany(r => r.Answers)
.HasForeignKey(a => a.ResponseId);
.HasForeignKey(a => a.ResponseId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Answer>()
.HasOne(a => a.Question)
.WithMany()
.HasForeignKey(a => a.QuestionId);
.HasForeignKey(a => a.QuestionId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Answer>()
.HasOne(a => a.Choice)
.WithMany()
.HasForeignKey(a => a.ChoiceId);
.WithMany()
.HasForeignKey(a => a.ChoiceId)
.OnDelete(DeleteBehavior.Cascade);
}
}
}

View File

@@ -1,30 +0,0 @@
using survey_beta.DTOs.Create;
using survey_beta.DTOs.Default;
using survey_beta.Models;
namespace survey_beta.Mappers
{
public class AnswerMapper
{
public static AnswerDto ToDto(Answer answer)
{
return new AnswerDto
{
Id = answer.Id,
ResponseId = answer.ResponseId,
QuestionId = answer.QuestionId,
ChoiceId = answer.ChoiceId
};
}
public static Answer ToEntity(CreateAnswerDto dto)
{
return new Answer
{
Id = Guid.NewGuid().ToString(),
ResponseId = dto.ResponseId,
QuestionId = dto.QuestionId,
ChoiceId = dto.ChoiceId
};
}
}
}

View File

@@ -24,7 +24,6 @@ namespace survey_beta.Mappers
Id = Guid.NewGuid().ToString(),
Letter = dto.Letter,
Content = dto.Content,
QuestionId = dto.QuestionId
};
}
}

View File

@@ -14,7 +14,6 @@ namespace survey_beta.Mappers
Title = survey.Title,
Description = survey.Description,
Category = survey.Category,
ExpirationDate = survey.ExpirationDate,
IsPublished = survey.IsPublished,
AuthorId = survey.AuthorId
};

View File

@@ -0,0 +1,6 @@
namespace survey_beta.Mappers
{
public class UserInfoDto
{
}
}

View File

@@ -1,7 +1,8 @@
using survey_beta.DTOs.Create;
using Microsoft.AspNetCore.Identity;
using survey_beta.DTOs.Create;
using survey_beta.DTOs.Default;
using survey_beta.Models;
using System.Security.Cryptography;
namespace survey_beta.Mappers
{
public class UserMapper
@@ -12,31 +13,23 @@ namespace survey_beta.Mappers
{
Id = user.Id,
Email = user.Email,
Username = user.Username,
Username = user.UserName,
Fullname = user.Fullname
};
}
public static User ToEntity(CreateUserDto dto)
public static User ToEntity(CreateUserDto dto, IPasswordHasher<User> passwordHasher)
{
return new User
var user = new User
{
Id = Guid.NewGuid().ToString(),
Email = dto.Email,
Username = dto.Username,
UserName = dto.Username,
Fullname = dto.Fullname,
PasswordHash = HashPassword(dto.Password)
};
}
public static string HashPassword(string password)
{
using (var sha256 = SHA256.Create())
{
var passwordBytes = System.Text.Encoding.UTF8.GetBytes(password);
var hashBytes = sha256.ComputeHash(passwordBytes);
return Convert.ToBase64String(hashBytes);
}
user.PasswordHash = passwordHasher.HashPassword(user, dto.Password);
return user;
}
}
}

View File

@@ -0,0 +1,502 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using survey_beta.DataBaseContext;
#nullable disable
namespace survey_beta.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250128174252_Controllers")]
partial class Controllers
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ChoiceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ResponseId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ChoiceId");
b.HasIndex("QuestionId");
b.HasIndex("ResponseId");
b.ToTable("Answers");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Letter")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("QuestionId");
b.ToTable("Choices");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Questions");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Responses");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("AuthorId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("ExpirationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.ToTable("Surveys");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("Fullname")
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("Username")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.HasOne("survey_beta.Models.Choice", "Choice")
.WithMany()
.HasForeignKey("ChoiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany()
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Response", "Response")
.WithMany("Answers")
.HasForeignKey("ResponseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Choice");
b.Navigation("Question");
b.Navigation("Response");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany("Choices")
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Question");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Questions")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Responses")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.HasOne("survey_beta.Models.User", "Author")
.WithMany("Surveys")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Author");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Navigation("Choices");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Navigation("Answers");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Navigation("Questions");
b.Navigation("Responses");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Navigation("Surveys");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,332 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace survey_beta.Migrations
{
/// <inheritdoc />
public partial class Controllers : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Surveys_User_AuthorId",
table: "Surveys");
migrationBuilder.DropPrimaryKey(
name: "PK_User",
table: "User");
migrationBuilder.RenameTable(
name: "User",
newName: "AspNetUsers");
migrationBuilder.AlterColumn<string>(
name: "UserName",
table: "AspNetUsers",
type: "character varying(256)",
maxLength: 256,
nullable: true,
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "NormalizedUserName",
table: "AspNetUsers",
type: "character varying(256)",
maxLength: 256,
nullable: true,
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "NormalizedEmail",
table: "AspNetUsers",
type: "character varying(256)",
maxLength: 256,
nullable: true,
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Email",
table: "AspNetUsers",
type: "character varying(256)",
maxLength: 256,
nullable: true,
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AddPrimaryKey(
name: "PK_AspNetUsers",
table: "AspNetUsers",
column: "Id");
migrationBuilder.CreateTable(
name: "AspNetRoles",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
NormalizedName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
ConcurrencyStamp = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoles", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AspNetUserClaims",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
UserId = table.Column<string>(type: "text", nullable: false),
ClaimType = table.Column<string>(type: "text", nullable: true),
ClaimValue = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetUserClaims_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserLogins",
columns: table => new
{
LoginProvider = table.Column<string>(type: "text", nullable: false),
ProviderKey = table.Column<string>(type: "text", nullable: false),
ProviderDisplayName = table.Column<string>(type: "text", nullable: true),
UserId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
table.ForeignKey(
name: "FK_AspNetUserLogins_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserTokens",
columns: table => new
{
UserId = table.Column<string>(type: "text", nullable: false),
LoginProvider = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Value = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
table.ForeignKey(
name: "FK_AspNetUserTokens_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetRoleClaims",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
RoleId = table.Column<string>(type: "text", nullable: false),
ClaimType = table.Column<string>(type: "text", nullable: true),
ClaimValue = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
table.ForeignKey(
name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AspNetUserRoles",
columns: table => new
{
UserId = table.Column<string>(type: "text", nullable: false),
RoleId = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
column: x => x.RoleId,
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AspNetUserRoles_AspNetUsers_UserId",
column: x => x.UserId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "EmailIndex",
table: "AspNetUsers",
column: "NormalizedEmail");
migrationBuilder.CreateIndex(
name: "UserNameIndex",
table: "AspNetUsers",
column: "NormalizedUserName",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_AspNetRoleClaims_RoleId",
table: "AspNetRoleClaims",
column: "RoleId");
migrationBuilder.CreateIndex(
name: "RoleNameIndex",
table: "AspNetRoles",
column: "NormalizedName",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_AspNetUserClaims_UserId",
table: "AspNetUserClaims",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserLogins_UserId",
table: "AspNetUserLogins",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_AspNetUserRoles_RoleId",
table: "AspNetUserRoles",
column: "RoleId");
migrationBuilder.AddForeignKey(
name: "FK_Surveys_AspNetUsers_AuthorId",
table: "Surveys",
column: "AuthorId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Surveys_AspNetUsers_AuthorId",
table: "Surveys");
migrationBuilder.DropTable(
name: "AspNetRoleClaims");
migrationBuilder.DropTable(
name: "AspNetUserClaims");
migrationBuilder.DropTable(
name: "AspNetUserLogins");
migrationBuilder.DropTable(
name: "AspNetUserRoles");
migrationBuilder.DropTable(
name: "AspNetUserTokens");
migrationBuilder.DropTable(
name: "AspNetRoles");
migrationBuilder.DropPrimaryKey(
name: "PK_AspNetUsers",
table: "AspNetUsers");
migrationBuilder.DropIndex(
name: "EmailIndex",
table: "AspNetUsers");
migrationBuilder.DropIndex(
name: "UserNameIndex",
table: "AspNetUsers");
migrationBuilder.RenameTable(
name: "AspNetUsers",
newName: "User");
migrationBuilder.AlterColumn<string>(
name: "UserName",
table: "User",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(256)",
oldMaxLength: 256,
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "NormalizedUserName",
table: "User",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(256)",
oldMaxLength: 256,
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "NormalizedEmail",
table: "User",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(256)",
oldMaxLength: 256,
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Email",
table: "User",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(256)",
oldMaxLength: 256,
oldNullable: true);
migrationBuilder.AddPrimaryKey(
name: "PK_User",
table: "User",
column: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Surveys_User_AuthorId",
table: "Surveys",
column: "AuthorId",
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@@ -0,0 +1,500 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using survey_beta.DataBaseContext;
#nullable disable
namespace survey_beta.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250131114349_ControllersServices")]
partial class ControllersServices
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ChoiceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ResponseId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ChoiceId");
b.HasIndex("QuestionId");
b.HasIndex("ResponseId");
b.ToTable("Answers");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Letter")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("QuestionId");
b.ToTable("Choices");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Questions");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Responses");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("AuthorId")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("ExpirationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.ToTable("Surveys");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("Fullname")
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.HasOne("survey_beta.Models.Choice", "Choice")
.WithMany()
.HasForeignKey("ChoiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany()
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Response", "Response")
.WithMany("Answers")
.HasForeignKey("ResponseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Choice");
b.Navigation("Question");
b.Navigation("Response");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany("Choices")
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Question");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Questions")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Responses")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.HasOne("survey_beta.Models.User", "Author")
.WithMany("Surveys")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Author");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Navigation("Choices");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Navigation("Answers");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Navigation("Questions");
b.Navigation("Responses");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Navigation("Surveys");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,77 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace survey_beta.Migrations
{
/// <inheritdoc />
public partial class ControllersServices : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "UserName",
table: "AspNetUsers");
migrationBuilder.RenameColumn(
name: "Username",
table: "AspNetUsers",
newName: "UserName");
migrationBuilder.AlterColumn<string>(
name: "AuthorId",
table: "Surveys",
type: "character varying(255)",
maxLength: 255,
nullable: false,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "UserName",
table: "AspNetUsers",
type: "character varying(256)",
maxLength: 256,
nullable: true,
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "UserName",
table: "AspNetUsers",
newName: "Username");
migrationBuilder.AlterColumn<string>(
name: "AuthorId",
table: "Surveys",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(255)",
oldMaxLength: 255);
migrationBuilder.AlterColumn<string>(
name: "Username",
table: "AspNetUsers",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(256)",
oldMaxLength: 256,
oldNullable: true);
migrationBuilder.AddColumn<string>(
name: "UserName",
table: "AspNetUsers",
type: "character varying(256)",
maxLength: 256,
nullable: true);
}
}
}

View File

@@ -0,0 +1,560 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using survey_beta.DataBaseContext;
#nullable disable
namespace survey_beta.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250131180518_ControllersServices2")]
partial class ControllersServices2
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Surveys", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("AuthorId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime?>("ExpirationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.ToTable("Surveys");
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ChoiceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ResponseId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ChoiceId");
b.HasIndex("QuestionId");
b.HasIndex("ResponseId");
b.ToTable("Answers");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Letter")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("QuestionId");
b.ToTable("Choices");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveysId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.HasIndex("SurveysId");
b.ToTable("Questions");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Responses");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("text");
b.Property<string>("AuthorId")
.IsRequired()
.HasMaxLength(255)
.HasColumnType("character varying(255)");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("ExpirationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.ToTable("Survey");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("Fullname")
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Surveys", b =>
{
b.HasOne("survey_beta.Models.User", "Author")
.WithMany()
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Author");
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.HasOne("survey_beta.Models.Choice", "Choice")
.WithMany()
.HasForeignKey("ChoiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany()
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Response", "Response")
.WithMany("Answers")
.HasForeignKey("ResponseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Choice");
b.Navigation("Question");
b.Navigation("Response");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany("Choices")
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Question");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Questions")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Surveys", null)
.WithMany("Questions")
.HasForeignKey("SurveysId");
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Responses")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.HasOne("survey_beta.Models.User", "Author")
.WithMany("Surveys")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Author");
});
modelBuilder.Entity("Surveys", b =>
{
b.Navigation("Questions");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Navigation("Choices");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Navigation("Answers");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Navigation("Questions");
b.Navigation("Responses");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Navigation("Surveys");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,164 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace survey_beta.Migrations
{
/// <inheritdoc />
public partial class ControllersServices2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Questions_Surveys_SurveyId",
table: "Questions");
migrationBuilder.DropForeignKey(
name: "FK_Responses_Surveys_SurveyId",
table: "Responses");
migrationBuilder.AlterColumn<DateTime>(
name: "ExpirationDate",
table: "Surveys",
type: "timestamp with time zone",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone");
migrationBuilder.AlterColumn<string>(
name: "AuthorId",
table: "Surveys",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(255)",
oldMaxLength: 255);
migrationBuilder.AddColumn<string>(
name: "SurveysId",
table: "Questions",
type: "text",
nullable: true);
migrationBuilder.CreateTable(
name: "Survey",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
Title = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: false),
Category = table.Column<string>(type: "text", nullable: false),
ExpirationDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
IsPublished = table.Column<bool>(type: "boolean", nullable: false),
AuthorId = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Survey", x => x.Id);
table.ForeignKey(
name: "FK_Survey_AspNetUsers_AuthorId",
column: x => x.AuthorId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Questions_SurveysId",
table: "Questions",
column: "SurveysId");
migrationBuilder.CreateIndex(
name: "IX_Survey_AuthorId",
table: "Survey",
column: "AuthorId");
migrationBuilder.AddForeignKey(
name: "FK_Questions_Survey_SurveyId",
table: "Questions",
column: "SurveyId",
principalTable: "Survey",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Questions_Surveys_SurveysId",
table: "Questions",
column: "SurveysId",
principalTable: "Surveys",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Responses_Survey_SurveyId",
table: "Responses",
column: "SurveyId",
principalTable: "Survey",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Questions_Survey_SurveyId",
table: "Questions");
migrationBuilder.DropForeignKey(
name: "FK_Questions_Surveys_SurveysId",
table: "Questions");
migrationBuilder.DropForeignKey(
name: "FK_Responses_Survey_SurveyId",
table: "Responses");
migrationBuilder.DropTable(
name: "Survey");
migrationBuilder.DropIndex(
name: "IX_Questions_SurveysId",
table: "Questions");
migrationBuilder.DropColumn(
name: "SurveysId",
table: "Questions");
migrationBuilder.AlterColumn<DateTime>(
name: "ExpirationDate",
table: "Surveys",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
oldClrType: typeof(DateTime),
oldType: "timestamp with time zone",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "AuthorId",
table: "Surveys",
type: "character varying(255)",
maxLength: 255,
nullable: false,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AddForeignKey(
name: "FK_Questions_Surveys_SurveyId",
table: "Questions",
column: "SurveyId",
principalTable: "Surveys",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Responses_Surveys_SurveyId",
table: "Responses",
column: "SurveyId",
principalTable: "Surveys",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@@ -0,0 +1,500 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using survey_beta.DataBaseContext;
#nullable disable
namespace survey_beta.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250131190914_Con")]
partial class Con
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ChoiceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ResponseId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ChoiceId");
b.HasIndex("QuestionId");
b.HasIndex("ResponseId");
b.ToTable("Answers");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Letter")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("QuestionId");
b.ToTable("Choices");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Questions");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Responses");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("AuthorId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime?>("ExpirationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.ToTable("Surveys");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("Fullname")
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("Username")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.HasOne("survey_beta.Models.Choice", "Choice")
.WithMany()
.HasForeignKey("ChoiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany()
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Response", "Response")
.WithMany("Answers")
.HasForeignKey("ResponseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Choice");
b.Navigation("Question");
b.Navigation("Response");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany("Choices")
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Question");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Questions")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany()
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.HasOne("survey_beta.Models.User", "Author")
.WithMany("Surveys")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Author");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Navigation("Choices");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Navigation("Answers");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Navigation("Questions");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Navigation("Surveys");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,169 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace survey_beta.Migrations
{
/// <inheritdoc />
public partial class Con : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Questions_Survey_SurveyId",
table: "Questions");
migrationBuilder.DropForeignKey(
name: "FK_Questions_Surveys_SurveysId",
table: "Questions");
migrationBuilder.DropForeignKey(
name: "FK_Responses_Survey_SurveyId",
table: "Responses");
migrationBuilder.DropTable(
name: "Survey");
migrationBuilder.DropIndex(
name: "IX_Questions_SurveysId",
table: "Questions");
migrationBuilder.DropColumn(
name: "SurveysId",
table: "Questions");
migrationBuilder.RenameColumn(
name: "UserName",
table: "AspNetUsers",
newName: "Username");
migrationBuilder.AlterColumn<string>(
name: "Username",
table: "AspNetUsers",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(256)",
oldMaxLength: 256,
oldNullable: true);
migrationBuilder.AddColumn<string>(
name: "UserName",
table: "AspNetUsers",
type: "character varying(256)",
maxLength: 256,
nullable: true);
migrationBuilder.AddForeignKey(
name: "FK_Questions_Surveys_SurveyId",
table: "Questions",
column: "SurveyId",
principalTable: "Surveys",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Responses_Surveys_SurveyId",
table: "Responses",
column: "SurveyId",
principalTable: "Surveys",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Questions_Surveys_SurveyId",
table: "Questions");
migrationBuilder.DropForeignKey(
name: "FK_Responses_Surveys_SurveyId",
table: "Responses");
migrationBuilder.DropColumn(
name: "UserName",
table: "AspNetUsers");
migrationBuilder.RenameColumn(
name: "Username",
table: "AspNetUsers",
newName: "UserName");
migrationBuilder.AddColumn<string>(
name: "SurveysId",
table: "Questions",
type: "text",
nullable: true);
migrationBuilder.AlterColumn<string>(
name: "UserName",
table: "AspNetUsers",
type: "character varying(256)",
maxLength: 256,
nullable: true,
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.CreateTable(
name: "Survey",
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
AuthorId = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),
Category = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: false),
ExpirationDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
IsPublished = table.Column<bool>(type: "boolean", nullable: false),
Title = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Survey", x => x.Id);
table.ForeignKey(
name: "FK_Survey_AspNetUsers_AuthorId",
column: x => x.AuthorId,
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Questions_SurveysId",
table: "Questions",
column: "SurveysId");
migrationBuilder.CreateIndex(
name: "IX_Survey_AuthorId",
table: "Survey",
column: "AuthorId");
migrationBuilder.AddForeignKey(
name: "FK_Questions_Survey_SurveyId",
table: "Questions",
column: "SurveyId",
principalTable: "Survey",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Questions_Surveys_SurveysId",
table: "Questions",
column: "SurveysId",
principalTable: "Surveys",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Responses_Survey_SurveyId",
table: "Responses",
column: "SurveyId",
principalTable: "Survey",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
}
}

View File

@@ -0,0 +1,498 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using survey_beta.DataBaseContext;
#nullable disable
namespace survey_beta.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250131192348_AddFullnameToUser")]
partial class AddFullnameToUser
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ChoiceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ResponseId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ChoiceId");
b.HasIndex("QuestionId");
b.HasIndex("ResponseId");
b.ToTable("Answers");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Letter")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("QuestionId");
b.ToTable("Choices");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Questions");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Responses");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("AuthorId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime?>("ExpirationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.ToTable("Surveys");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("Fullname")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.HasOne("survey_beta.Models.Choice", "Choice")
.WithMany()
.HasForeignKey("ChoiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany()
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Response", "Response")
.WithMany("Answers")
.HasForeignKey("ResponseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Choice");
b.Navigation("Question");
b.Navigation("Response");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany("Choices")
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Question");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Questions")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany()
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.HasOne("survey_beta.Models.User", "Author")
.WithMany("Surveys")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Author");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Navigation("Choices");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Navigation("Answers");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Navigation("Questions");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Navigation("Surveys");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,77 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace survey_beta.Migrations
{
/// <inheritdoc />
public partial class AddFullnameToUser : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "UserName",
table: "AspNetUsers");
migrationBuilder.RenameColumn(
name: "Username",
table: "AspNetUsers",
newName: "UserName");
migrationBuilder.AlterColumn<string>(
name: "UserName",
table: "AspNetUsers",
type: "character varying(256)",
maxLength: 256,
nullable: true,
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Fullname",
table: "AspNetUsers",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "UserName",
table: "AspNetUsers",
newName: "Username");
migrationBuilder.AlterColumn<string>(
name: "Username",
table: "AspNetUsers",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "character varying(256)",
oldMaxLength: 256,
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Fullname",
table: "AspNetUsers",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AddColumn<string>(
name: "UserName",
table: "AspNetUsers",
type: "character varying(256)",
maxLength: 256,
nullable: true);
}
}
}

View File

@@ -0,0 +1,509 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using survey_beta.DataBaseContext;
#nullable disable
namespace survey_beta.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250131221823_responses")]
partial class responses
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ChoiceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ResponseId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ChoiceId");
b.HasIndex("QuestionId");
b.HasIndex("ResponseId");
b.ToTable("Answers");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Letter")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("QuestionId");
b.ToTable("Choices");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Questions");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Responses");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("AuthorId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime?>("ExpirationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.ToTable("Surveys");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("Fullname")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.HasOne("survey_beta.Models.Choice", "Choice")
.WithMany()
.HasForeignKey("ChoiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany()
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Response", "Response")
.WithMany("Answers")
.HasForeignKey("ResponseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Choice");
b.Navigation("Question");
b.Navigation("Response");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany("Choices")
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Question");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Questions")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany()
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.HasOne("survey_beta.Models.User", "Author")
.WithMany("Surveys")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Author");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Navigation("Choices");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Navigation("Answers");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Navigation("Questions");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Navigation("Surveys");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,52 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace survey_beta.Migrations
{
/// <inheritdoc />
public partial class responses : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "CreatedAt",
table: "Responses",
type: "timestamp with time zone",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
migrationBuilder.AddColumn<string>(
name: "Text",
table: "Questions",
type: "text",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
name: "Type",
table: "Questions",
type: "text",
nullable: false,
defaultValue: "");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CreatedAt",
table: "Responses");
migrationBuilder.DropColumn(
name: "Text",
table: "Questions");
migrationBuilder.DropColumn(
name: "Type",
table: "Questions");
}
}
}

View File

@@ -0,0 +1,507 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using survey_beta.DataBaseContext;
#nullable disable
namespace survey_beta.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250201210414_Serviecs")]
partial class Serviecs
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ChoiceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ResponseId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ChoiceId");
b.HasIndex("QuestionId");
b.HasIndex("ResponseId");
b.ToTable("Answers");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Letter")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("QuestionId");
b.ToTable("Choices");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Questions");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Responses");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("AuthorId")
.HasColumnType("text");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime?>("ExpirationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.ToTable("Surveys");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("Fullname")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.HasOne("survey_beta.Models.Choice", "Choice")
.WithMany()
.HasForeignKey("ChoiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany()
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Response", "Response")
.WithMany("Answers")
.HasForeignKey("ResponseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Choice");
b.Navigation("Question");
b.Navigation("Response");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany("Choices")
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Question");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Questions")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany()
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.HasOne("survey_beta.Models.User", "Author")
.WithMany("Surveys")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Author");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Navigation("Choices");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Navigation("Answers");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Navigation("Questions");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Navigation("Surveys");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace survey_beta.Migrations
{
/// <inheritdoc />
public partial class Serviecs : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "AuthorId",
table: "Surveys",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "AuthorId",
table: "Surveys",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
}
}
}

View File

@@ -0,0 +1,495 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using survey_beta.DataBaseContext;
#nullable disable
namespace survey_beta.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250201210920_Serviecs2")]
partial class Serviecs2
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ChoiceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ResponseId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ChoiceId");
b.HasIndex("QuestionId");
b.HasIndex("ResponseId");
b.ToTable("Answers");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.HasColumnType("text");
b.Property<string>("Letter")
.HasColumnType("text");
b.Property<string>("QuestionId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("QuestionId");
b.ToTable("Choices");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.HasColumnType("text");
b.Property<string>("SurveyId")
.HasColumnType("text");
b.Property<string>("Text")
.HasColumnType("text");
b.Property<string>("Type")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Questions");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Responses");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("AuthorId")
.HasColumnType("text");
b.Property<string>("Category")
.HasColumnType("text");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<DateTime?>("ExpirationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<string>("Title")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.ToTable("Surveys");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("Fullname")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.HasOne("survey_beta.Models.Choice", "Choice")
.WithMany()
.HasForeignKey("ChoiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany()
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Response", "Response")
.WithMany("Answers")
.HasForeignKey("ResponseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Choice");
b.Navigation("Question");
b.Navigation("Response");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany("Choices")
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Question");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Questions")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany()
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.HasOne("survey_beta.Models.User", "Author")
.WithMany("Surveys")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Author");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Navigation("Choices");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Navigation("Answers");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Navigation("Questions");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Navigation("Surveys");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,198 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace survey_beta.Migrations
{
/// <inheritdoc />
public partial class Serviecs2 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Title",
table: "Surveys",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "Description",
table: "Surveys",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "Category",
table: "Surveys",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "Type",
table: "Questions",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "Text",
table: "Questions",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "SurveyId",
table: "Questions",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "Content",
table: "Questions",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "QuestionId",
table: "Choices",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "Letter",
table: "Choices",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.AlterColumn<string>(
name: "Content",
table: "Choices",
type: "text",
nullable: true,
oldClrType: typeof(string),
oldType: "text");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Title",
table: "Surveys",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Description",
table: "Surveys",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Category",
table: "Surveys",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Type",
table: "Questions",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Text",
table: "Questions",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "SurveyId",
table: "Questions",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Content",
table: "Questions",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "QuestionId",
table: "Choices",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Letter",
table: "Choices",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
migrationBuilder.AlterColumn<string>(
name: "Content",
table: "Choices",
type: "text",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "text",
oldNullable: true);
}
}
}

View File

@@ -22,6 +22,138 @@ namespace survey_beta.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.Property<string>("Id")
@@ -56,15 +188,12 @@ namespace survey_beta.Migrations
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Letter")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
@@ -80,11 +209,15 @@ namespace survey_beta.Migrations
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Text")
.HasColumnType("text");
b.Property<string>("Type")
.HasColumnType("text");
b.HasKey("Id");
@@ -99,6 +232,9 @@ namespace survey_beta.Migrations
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("text");
@@ -120,25 +256,21 @@ namespace survey_beta.Migrations
.HasColumnType("text");
b.Property<string>("AuthorId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("ExpirationDate")
b.Property<DateTime?>("ExpirationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
@@ -157,15 +289,18 @@ namespace survey_beta.Migrations
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasColumnType("text");
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("Fullname")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
@@ -175,10 +310,12 @@ namespace survey_beta.Migrations
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasColumnType("text");
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasColumnType("text");
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
@@ -196,14 +333,70 @@ namespace survey_beta.Migrations
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasColumnType("text");
b.Property<string>("Username")
.HasColumnType("text");
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.ToTable("User");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
@@ -238,8 +431,7 @@ namespace survey_beta.Migrations
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany("Choices")
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Question");
});
@@ -249,8 +441,7 @@ namespace survey_beta.Migrations
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Questions")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Survey");
});
@@ -258,7 +449,7 @@ namespace survey_beta.Migrations
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Responses")
.WithMany()
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
@@ -271,8 +462,7 @@ namespace survey_beta.Migrations
b.HasOne("survey_beta.Models.User", "Author")
.WithMany("Surveys")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Author");
});
@@ -290,8 +480,6 @@ namespace survey_beta.Migrations
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Navigation("Questions");
b.Navigation("Responses");
});
modelBuilder.Entity("survey_beta.Models.User", b =>

View File

@@ -1,8 +1,10 @@
namespace survey_beta.Models
using System;
namespace survey_beta.Models
{
public class Answer
{
public string Id { get; set; }
public string Id { get; set; } = Guid.NewGuid().ToString();
public string ResponseId { get; set; }
public Response Response { get; set; }
public string QuestionId { get; set; }

View File

@@ -1,11 +1,13 @@
namespace survey_beta.Models
using System;
namespace survey_beta.Models
{
public class Choice
{
public string Id { get; set; }
public string Letter { get; set; }
public string Content { get; set; }
public string QuestionId { get; set; }
public Question Question { get; set; }
public string? Id { get; set; } = Guid.NewGuid().ToString();
public string? Letter { get; set; }
public string? Content { get; set; }
public string? QuestionId { get; set; }
public Question? Question { get; set; }
}
}

View File

@@ -1,11 +1,18 @@
namespace survey_beta.Models
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace survey_beta.Models
{
public class Question
{
public string Id { get; set; }
public string Content { get; set; }
public string SurveyId { get; set; }
public Survey Survey { get; set; }
public ICollection<Choice> Choices { get; set; }
public string? Id { get; set; } = Guid.NewGuid().ToString();
public string? Content { get; set; }
public string? Text { get; set; }
public string? Type { get; set; }
public string? SurveyId { get; set; }
[JsonIgnore]
public Survey? Survey { get; set; }
public ICollection<Choice> Choices { get; set; } = new List<Choice>();
}
}

View File

@@ -1,11 +1,15 @@
namespace survey_beta.Models
using System;
using System.Collections.Generic;
namespace survey_beta.Models
{
public class Response
{
public string Id { get; set; }
public string Id { get; set; } = Guid.NewGuid().ToString();
public string IpAddress { get; set; }
public string SurveyId { get; set; }
public Survey Survey { get; set; }
public ICollection<Answer> Answers { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public ICollection<Answer> Answers { get; set; } = new List<Answer>();
}
}

View File

@@ -1,16 +1,18 @@
namespace survey_beta.Models
using System;
using System.Collections.Generic;
namespace survey_beta.Models
{
public class Survey
{
public string Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Category { get; set; }
public DateTime ExpirationDate { get; set; }
{
public string? Id { get; set; } = Guid.NewGuid().ToString();
public string? Title { get; set; }
public string? Description { get; set; }
public string? Category { get; set; }
public DateTime? ExpirationDate { get; set; }
public bool IsPublished { get; set; }
public string AuthorId { get; set; }
public User Author { get; set; }
public string? AuthorId { get; set; }
public User? Author { get; set; }
public ICollection<Question> Questions { get; set; }
public ICollection<Response> Responses { get; set; }
}
}

View File

@@ -4,12 +4,7 @@ namespace survey_beta.Models
{
public class User : IdentityUser
{
public string? Id { get; set; }
public string? Username { get; set; }
public string? Fullname { get; set; }
public string? Email { get; set; }
public string? PasswordHash { get; set; }
public string Fullname { get; set; }
public ICollection<Survey> Surveys { get; set; } = new List<Survey>();
}
}

View File

@@ -1,42 +1,83 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.IdentityModel.Tokens;
using survey_beta.DataBaseContext;
using survey_beta.Models;
using survey_beta.Services;
using System.Text;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddIdentity<User, IdentityRole>()
.AddEntityFrameworkStores<AppDbContext>()
.AddDefaultTokenProviders();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.AddSecurityDefinition("Bearer", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
{
In = Microsoft.OpenApi.Models.ParameterLocation.Header,
Description = "Please enter JWT with Bearer into field",
Name = "Authorization",
Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey
});
c.AddSecurityRequirement(new Microsoft.OpenApi.Models.OpenApiSecurityRequirement
{
{
new Microsoft.OpenApi.Models.OpenApiSecurityScheme
{
Reference = new Microsoft.OpenApi.Models.OpenApiReference
{
Type = Microsoft.OpenApi.Models.ReferenceType.SecurityScheme,
Id = "Bearer"
}
},
new string[] {}
}
});
});
builder.Services.AddIdentity<User, IdentityRole>()
.AddEntityFrameworkStores<AppDbContext>()
.AddDefaultTokenProviders();
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidIssuer = builder.Configuration["Jwt:Issuer"],
ValidAudience = builder.Configuration["Jwt:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"]))
};
});
builder.Services.AddScoped<UsersServices>();
builder.Services.AddScoped<SurveyService>();
builder.Services.AddScoped<ResponsesService>();
builder.Services.AddScoped<AnalyticsServices>();
var app = builder.Build();
// Configure the HTTP request pipeline.
// HTTP request pipeline
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.MapControllers();
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
app.Run();

View File

@@ -1,6 +1,129 @@
namespace survey_beta.Services
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using survey_beta.DataBaseContext;
using survey_beta.DTOs.Update;
using survey_beta.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public class AnalyticsServices
{
public class AnalyticsServices
private readonly AppDbContext _context;
public AnalyticsServices(AppDbContext context)
{
_context = context;
}
public void UpdateAnalytics(string surveyId)
{
var responses = _context.Responses
.Where(r => r.SurveyId == surveyId)
.Include(r => r.Answers)
.ThenInclude(a => a.Choice)
.ToList();
var analyticsData = CalculateAnalytics(responses);
SaveAnalytics(surveyId, analyticsData);
}
private SurveyStats CalculateAnalytics(List<Response> responses)
{
var answerFrequency = new Dictionary<string, int>();
var questionFrequency = new Dictionary<string, int>();
foreach (var response in responses)
{
foreach (var answer in response.Answers)
{
var choiceText = answer.Choice?.Letter;
if (choiceText != null)
{
if (answerFrequency.ContainsKey(choiceText))
{
answerFrequency[choiceText]++;
}
else
{
answerFrequency[choiceText] = 1;
}
}
if (questionFrequency.ContainsKey(answer.Question?.Text))
{
questionFrequency[answer.Question.Text]++;
}
else
{
questionFrequency[answer.Question.Text] = 1;
}
}
}
return new SurveyStats
{
SurveyId = responses.FirstOrDefault()?.SurveyId,
TotalResponses = responses.Count,
AnswerFrequency = answerFrequency,
QuestionFrequency = questionFrequency
};
}
private void SaveAnalytics(string surveyId, SurveyStats analyticsData)
{
var analytics = new SurveyAnalytics
{
SurveyId = surveyId,
TotalResponses = analyticsData.TotalResponses,
CreatedAt = DateTime.UtcNow,
};
_context.Add(analytics);
_context.SaveChanges();
}
public SurveyStats GetAggregatedSurveyResponses(string surveyId)
{
var responses = _context.Responses
.Where(r => r.SurveyId == surveyId)
.Include(r => r.Answers)
.ThenInclude(a => a.Choice)
.ToList();
return CalculateAnalytics(responses);
}
public IActionResult ExportSurveyDataToCsv(string surveyId)
{
var responses = _context.Responses
.Where(r => r.SurveyId == surveyId)
.Include(r => r.Answers)
.ThenInclude(a => a.Choice)
.ToList();
if (responses == null || responses.Count == 0)
{
return new ObjectResult("No responses found for this survey.")
{
StatusCode = 404
};
}
var csvData = new StringWriter();
var csvHeader = "ResponseId,Question,ChoiceText";
csvData.WriteLine(csvHeader);
foreach (var response in responses)
{
foreach (var answer in response.Answers)
{
var choiceText = answer.Choice?.Letter ?? "No Choice";
var csvLine = $"{response.Id},{answer.Question?.Text},{choiceText}";
csvData.WriteLine(csvLine);
}
}
var fileName = $"{surveyId}_responses.csv";
var fileBytes = System.Text.Encoding.UTF8.GetBytes(csvData.ToString());
return new FileContentResult(fileBytes, "text/csv")
{
FileDownloadName = fileName
};
}
}

View File

@@ -1,6 +1,44 @@
namespace survey_beta.Services
using Microsoft.EntityFrameworkCore;
using survey_beta.DataBaseContext;
using survey_beta.DTOs.Default;
using survey_beta.DTOs.Response;
using survey_beta.Models;
using System;
using System.Collections.Generic;
using System.Linq;
public class ResponsesService
{
public class ResponsesServices
private readonly AppDbContext _context;
private readonly AnalyticsServices _analyticsService;
public ResponsesService(AppDbContext context, AnalyticsServices analyticsService)
{
_context = context;
_analyticsService = analyticsService;
}
}
public void AddResponse(CreatorResponseDto request)
{
var answers = request.Answers.Select(a => new AnswerDto
{
Question = a.Question,
AnswerText = a.AnswerText
}).ToList();

what's the point of the answers variable here?

what's the point of the answers variable here?
var response = new Response
{
SurveyId = request.SurveyId,
Id = request.Id,
CreatedAt = DateTime.UtcNow
};
_context.Responses.Add(response);
_context.SaveChanges();
}
public List<Response> GetSurveyResponses(string surveyId)
{
return _context.Responses
.Where(r => r.SurveyId == surveyId)
.Include(r => r.Answers)
.ToList();
}
}

View File

@@ -1,6 +1,92 @@
namespace survey_beta.Services
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using survey_beta.DataBaseContext;
using survey_beta.DTOs.Create;
using survey_beta.DTOs.Update;
using survey_beta.Models;
using System.Security.Claims;
public class SurveyService
{
public class SurveyServices
private readonly AppDbContext _context;
public SurveyService(AppDbContext context)
{
_context = context;
}
public async Task<Survey> GetSurveyByIdAsync(string id)
{
return await _context.Surveys
.Include(s => s.Questions)
.FirstOrDefaultAsync(s => s.Id == id);
}
public async Task<List<Survey>> GetUserSurveysAsync(string userId)
{
return await _context.Surveys.Where(s => s.AuthorId == userId).ToListAsync();
}
public async Task<Survey> CreateSurveyAsync(CreateSurveyDto request)
{
var survey = new Survey
{
Id = Guid.NewGuid().ToString(),
Title = request.Title,
Description = request.Description,
Category = request.Category,
ExpirationDate = request.ExpirationDate,
AuthorId = null,
Questions = request.Questions.Select(q => new Question
{
Id = Guid.NewGuid().ToString(),
Text = q.Content,
}).ToList()
};
_context.Surveys.Add(survey);
await _context.SaveChangesAsync();
return survey;
}
public async Task<bool> UpdateSurveyAsync(UpdateSurveyDto request)
{
var survey = await _context.Surveys.FindAsync(request.Id);
if (survey == null) return false;
survey.Title = request.Title;
survey.Description = request.Description;
survey.Category = request.Category;
survey.ExpirationDate = request.ExpirationDate;
survey.IsPublished = request.IsPublished;
await _context.SaveChangesAsync();
return true;
}
public async Task<bool> PublishSurveyAsync(string id)
{
var survey = await _context.Surveys.FindAsync(id);
if (survey == null) return false;
survey.IsPublished = true;
await _context.SaveChangesAsync();
return true;
}
public async Task<bool> UnpublishSurveyAsync(string id)
{
var survey = await _context.Surveys.FindAsync(id);
if (survey == null) return false;
survey.IsPublished = false;
await _context.SaveChangesAsync();
return true;
}
public async Task<bool> DeleteSurveyAsync(string id)
{
var survey = await _context.Surveys.FindAsync(id);
if (survey == null) return false;
_context.Surveys.Remove(survey);
await _context.SaveChangesAsync();
return true;
}
}

View File

@@ -1,6 +1,143 @@
namespace survey_beta.Services
using Microsoft.AspNetCore.Identity;
using Microsoft.IdentityModel.Tokens;
using survey_beta.DTOs.Create;
using survey_beta.DTOs.Default;
using survey_beta.Models;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using System.Text;
public class UsersServices
{
public class UsersServices
private readonly UserManager<User> _userManager;
private readonly SignInManager<User> _signInManager;
private readonly IConfiguration _configuration;
public UsersServices(UserManager<User> userManager, SignInManager<User> signInManager, IConfiguration configuration)
{
_userManager = userManager;
_signInManager = signInManager;
_configuration = configuration;
}
public async Task<UserDto> CreateUserAsync(CreateUserDto createUserDto)
{
var existingUser = await _userManager.FindByEmailAsync(createUserDto.Email);
if (existingUser != null)
{
throw new Exception("User with this email already exists.");
}
var user = new User
{
UserName = createUserDto.Username,
Email = createUserDto.Email,
Fullname = createUserDto.Fullname
};
var result = await _userManager.CreateAsync(user, createUserDto.Password);
if (!result.Succeeded)
{
throw new Exception("Failed to create user: " + string.Join(", ", result.Errors.Select(e => e.Description)));
}
return new UserDto
{
Id = user.Id,
Email = user.Email,
Username = user.UserName,
Fullname = user.Fullname,
Token = GenerateJwtToken(user)
};
}
public async Task<UserDto> SignInAsync(LoginDto loginDto)
{
var user = await _userManager.FindByNameAsync(loginDto.Username);
if (user == null)
{
throw new Exception("Invalid login attempt.");
}
var result = await _signInManager.PasswordSignInAsync(user, loginDto.Password, false, false);
if (!result.Succeeded)
{
throw new Exception("Invalid login attempt.");
}
return new UserDto
{
Id = user.Id,
Email = user.Email,
Username = user.UserName,
Fullname = user.Fullname,
Token = GenerateJwtToken(user)
};
}
public async Task<UserDto> GetUserByIdAsync(string userId)
{
var user = await _userManager.FindByIdAsync(userId);
if (user == null)
{
throw new Exception("User not found.");
}
return new UserDto
{
Id = user.Id,
Email = user.Email,
Username = user.UserName,
Fullname = user.Fullname
};
}
public async Task<UserDto> GetUserByUsernameAsync(string username)
{
var user = await _userManager.FindByNameAsync(username);
if (user == null)
{
throw new Exception("User not found.");
}
return new UserDto
{
Id = user.Id,
Email = user.Email,
Username = user.UserName,
Fullname = user.Fullname
};
}
private string GenerateJwtToken(User user)
{
var claims = new[]
{
new Claim(JwtRegisteredClaimNames.Sub, user.UserName),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
new Claim(ClaimTypes.Email, user.Email),
new Claim(ClaimTypes.Name, user.Fullname)
};
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["Jwt:Key"]));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var token = new JwtSecurityToken(
issuer: _configuration["Jwt:Issuer"],
audience: _configuration["Jwt:Audience"],
claims: claims,
expires: DateTime.Now.AddMinutes(30),
signingCredentials: creds);
return new JwtSecurityTokenHandler().WriteToken(token);
}
public async Task<List<UserDto>> GetAllUsersAsync()
{
var users = _userManager.Users.ToList();
var userDtos = users.Select(user => new UserDto
{
Id = user.Id,
Email = user.Email,
Username = user.UserName,
Fullname = user.Fullname
}).ToList();
return userDtos;
}
}

View File

@@ -1,12 +1,11 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
"Jwt": {
"Key": "YourSuperSecretKeyYourSuperSecretKey",
"Issuer": "YourIssuer",
"Audience": "YourAudience"
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Database=SurveyDB;Username=postgre;Password=MAJEDali645"
"DefaultConnection": "Host=localhost;Database=SurveyBeta;Username=postgres;Password=MAJEDali645"
}
}

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -0,0 +1,11 @@
{
"Jwt": {
"Key": "YourSuperSecretKeyYourSuperSecretKey",
"Issuer": "YourIssuer",
"Audience": "YourAudience"
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Database=SurveyBeta;Username=postgres;Password=MAJEDali645"
}
}