mirror of
https://github.com/jcreek/WhoAtX.git
synced 2026-07-13 03:03:44 +00:00
feat(#10): Add user creation and editing
This commit is contained in:
@@ -13,10 +13,45 @@ namespace WhoAtX.Controllers
|
|||||||
_context = context;
|
_context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Profile()
|
private UserProfileViewModel MapUserProfileToViewModel(UserProfile userProfile)
|
||||||
{
|
{
|
||||||
// Retrieve user profile data from the database
|
var userProfileViewModel = new UserProfileViewModel
|
||||||
var userProfile = _context.UserProfiles.FirstOrDefault();
|
{
|
||||||
|
Id = userProfile.Id,
|
||||||
|
Name = userProfile.Name,
|
||||||
|
Pronouns = userProfile.Pronouns,
|
||||||
|
NamePronunciationPath = userProfile.NamePronunciationPath,
|
||||||
|
AreasOfKnowledge = userProfile.AreasOfKnowledge,
|
||||||
|
Projects = userProfile.Projects,
|
||||||
|
Team = userProfile.Team,
|
||||||
|
WorkingHours = userProfile.WorkingHours,
|
||||||
|
TimeZone = userProfile.TimeZone,
|
||||||
|
};
|
||||||
|
|
||||||
|
return userProfileViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private UserProfile MapViewModelToUserProfile(UserProfileViewModel userProfileViewModel)
|
||||||
|
{
|
||||||
|
var userProfile = new UserProfile
|
||||||
|
{
|
||||||
|
Id = userProfileViewModel.Id,
|
||||||
|
Name = userProfileViewModel.Name,
|
||||||
|
Pronouns = userProfileViewModel.Pronouns,
|
||||||
|
NamePronunciationPath = userProfileViewModel.NamePronunciationPath,
|
||||||
|
AreasOfKnowledge = userProfileViewModel.AreasOfKnowledge,
|
||||||
|
Projects = userProfileViewModel.Projects,
|
||||||
|
Team = userProfileViewModel.Team,
|
||||||
|
WorkingHours = userProfileViewModel.WorkingHours,
|
||||||
|
TimeZone = userProfileViewModel.TimeZone,
|
||||||
|
};
|
||||||
|
|
||||||
|
return userProfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult Profile(int id)
|
||||||
|
{
|
||||||
|
var userProfile = _context.UserProfiles.Find(id);
|
||||||
|
|
||||||
if (userProfile is null)
|
if (userProfile is null)
|
||||||
{
|
{
|
||||||
@@ -39,21 +74,63 @@ namespace WhoAtX.Controllers
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Map UserProfile to UserProfileViewModel
|
var userProfileViewModel = MapUserProfileToViewModel(userProfile);
|
||||||
var userProfileViewModel = new UserProfileViewModel
|
|
||||||
{
|
|
||||||
Name = userProfile.Name,
|
|
||||||
Pronouns = userProfile.Pronouns,
|
|
||||||
NamePronunciationPath = userProfile.NamePronunciationPath,
|
|
||||||
AreasOfKnowledge = userProfile.AreasOfKnowledge,
|
|
||||||
Projects = userProfile.Projects,
|
|
||||||
Team = userProfile.Team,
|
|
||||||
WorkingHours = userProfile.WorkingHours,
|
|
||||||
TimeZone = userProfile.TimeZone,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Pass the user profile data to the view
|
// Pass the user profile data to the view
|
||||||
return View(userProfileViewModel);
|
return View(userProfileViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IActionResult New()
|
||||||
|
{
|
||||||
|
return View(new UserProfileViewModel());
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult CreateUserProfile(UserProfileViewModel userProfileViewModel)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var userProfile = MapViewModelToUserProfile(userProfileViewModel);
|
||||||
|
|
||||||
|
_context.UserProfiles.Add(userProfile);
|
||||||
|
_context.SaveChanges();
|
||||||
|
|
||||||
|
return RedirectToAction("Profile");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If ModelState is not valid, return to the create page with validation errors
|
||||||
|
return View("New", userProfileViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult Edit(int id)
|
||||||
|
{
|
||||||
|
var userProfile = _context.UserProfiles.Find(id);
|
||||||
|
|
||||||
|
if (userProfile == null)
|
||||||
|
{
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
var userProfileViewModel = MapUserProfileToViewModel(userProfile);
|
||||||
|
|
||||||
|
return View(userProfileViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult UpdateUserProfile(UserProfileViewModel userProfileViewModel)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var userProfile = MapViewModelToUserProfile(userProfileViewModel);
|
||||||
|
|
||||||
|
_context.UserProfiles.Update(userProfile);
|
||||||
|
_context.SaveChanges();
|
||||||
|
|
||||||
|
return RedirectToAction("Profile");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If ModelState is not valid, return to the edit page with validation errors
|
||||||
|
return View("Edit", userProfileViewModel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -10,7 +10,7 @@ using WhoAtX.Data;
|
|||||||
namespace WhoAtX.Migrations
|
namespace WhoAtX.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ApplicationDbContext))]
|
[DbContext(typeof(ApplicationDbContext))]
|
||||||
[Migration("20230914205826_InitialCreate")]
|
[Migration("20230915100710_InitialCreate")]
|
||||||
partial class InitialCreate
|
partial class InitialCreate
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -34,7 +34,6 @@ namespace WhoAtX.Migrations
|
|||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("NamePronunciationPath")
|
b.Property<string>("NamePronunciationPath")
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Projects")
|
b.Property<string>("Projects")
|
||||||
+1
-1
@@ -18,7 +18,7 @@ namespace WhoAtX.Migrations
|
|||||||
.Annotation("Sqlite:Autoincrement", true),
|
.Annotation("Sqlite:Autoincrement", true),
|
||||||
Name = table.Column<string>(type: "TEXT", nullable: false),
|
Name = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
Pronouns = table.Column<string>(type: "TEXT", nullable: false),
|
Pronouns = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
NamePronunciationPath = table.Column<string>(type: "TEXT", nullable: false),
|
NamePronunciationPath = table.Column<string>(type: "TEXT", nullable: true),
|
||||||
AreasOfKnowledge = table.Column<string>(type: "TEXT", nullable: false),
|
AreasOfKnowledge = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
Projects = table.Column<string>(type: "TEXT", nullable: false),
|
Projects = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
Team = table.Column<string>(type: "TEXT", nullable: false),
|
Team = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
@@ -31,7 +31,6 @@ namespace WhoAtX.Migrations
|
|||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("NamePronunciationPath")
|
b.Property<string>("NamePronunciationPath")
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("TEXT");
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
b.Property<string>("Projects")
|
b.Property<string>("Projects")
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ public class UserProfile
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Pronouns { get; set; }
|
public string Pronouns { get; set; }
|
||||||
public string NamePronunciationPath { get; set; }
|
public string? NamePronunciationPath { get; set; }
|
||||||
public string AreasOfKnowledge { get; set; }
|
public string AreasOfKnowledge { get; set; }
|
||||||
public string Projects { get; set; }
|
public string Projects { get; set; }
|
||||||
public string Team { get; set; }
|
public string Team { get; set; }
|
||||||
|
|||||||
@@ -2,17 +2,18 @@ namespace WhoAtX.Models;
|
|||||||
|
|
||||||
public class UserProfileViewModel
|
public class UserProfileViewModel
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
public int Id { get; set; }
|
||||||
public string Pronouns { get; set; }
|
public string? Name { get; set; }
|
||||||
public string NamePronunciationPath { get; set; }
|
public string? Pronouns { get; set; }
|
||||||
|
public string? NamePronunciationPath { get; set; }
|
||||||
|
|
||||||
// Add more personal details here
|
// Add more personal details here
|
||||||
|
|
||||||
public string AreasOfKnowledge { get; set; }
|
public string? AreasOfKnowledge { get; set; }
|
||||||
public string Projects { get; set; }
|
public string? Projects { get; set; }
|
||||||
public string Team { get; set; }
|
public string? Team { get; set; }
|
||||||
public string WorkingHours { get; set; }
|
public string? WorkingHours { get; set; }
|
||||||
public string TimeZone { get; set; }
|
public string? TimeZone { get; set; }
|
||||||
|
|
||||||
// Add more professional details here
|
// Add more professional details here
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,12 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="User" asp-action="Profile">User Profile</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="User" asp-action="Profile">User Profile</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="User" asp-action="New">New User Profile</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="User" asp-action="Edit">Edit User Profile</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
@model UserProfileViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Edit User Profile";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h1>Edit User Profile</h1>
|
||||||
|
|
||||||
|
@using (Html.BeginForm("UpdateUserProfile", "User", FormMethod.Post))
|
||||||
|
{
|
||||||
|
<input type="text" hidden id="Id" name="Id" value="@Model.Id">
|
||||||
|
<!-- Name -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="Name">Name:</label>
|
||||||
|
<input type="text" class="form-control" id="Name" name="Name" value="@Model.Name">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Pronouns -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="Pronouns">Pronouns:</label>
|
||||||
|
<input type="text" class="form-control" id="Pronouns" name="Pronouns" value="@Model.Pronouns">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@* <!-- Name Pronunciation Path --> *@
|
||||||
|
@* <div class="form-group"> *@
|
||||||
|
@* <label for="NamePronunciationPath">Name Pronunciation Path:</label> *@
|
||||||
|
@* <input type="text" class="form-control" id="NamePronunciationPath" name="NamePronunciationPath" value="@Model.NamePronunciationPath"> *@
|
||||||
|
@* </div> *@
|
||||||
|
|
||||||
|
<!-- Areas of Knowledge -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="AreasOfKnowledge">Areas of Knowledge:</label>
|
||||||
|
<input type="text" class="form-control" id="AreasOfKnowledge" name="AreasOfKnowledge" value="@Model.AreasOfKnowledge">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Projects -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="Projects">Projects:</label>
|
||||||
|
<input type="text" class="form-control" id="Projects" name="Projects" value="@Model.Projects">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Team -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="Team">Team:</label>
|
||||||
|
<input type="text" class="form-control" id="Team" name="Team" value="@Model.Team">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Working Hours -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="WorkingHours">Working Hours:</label>
|
||||||
|
<input type="text" class="form-control" id="WorkingHours" name="WorkingHours" value="@Model.WorkingHours">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Time Zone -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="TimeZone">Time Zone:</label>
|
||||||
|
<input type="text" class="form-control" id="TimeZone" name="TimeZone" value="@Model.TimeZone">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary">Update Profile</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
@model UserProfileViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Create New User Profile";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<h1>Create New User Profile</h1>
|
||||||
|
|
||||||
|
@using (Html.BeginForm("CreateUserProfile", "User", FormMethod.Post))
|
||||||
|
{
|
||||||
|
<!-- Name -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="Name">Name:</label>
|
||||||
|
<input type="text" class="form-control" id="Name" name="Name" value="@Model.Name">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Pronouns -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="Pronouns">Pronouns:</label>
|
||||||
|
<input type="text" class="form-control" id="Pronouns" name="Pronouns" value="@Model.Pronouns">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@* <!-- Name Pronunciation Path --> *@
|
||||||
|
@* <div class="form-group"> *@
|
||||||
|
@* <label for="NamePronunciationPath">Name Pronunciation Path:</label> *@
|
||||||
|
@* <input type="text" class="form-control" id="NamePronunciationPath" name="NamePronunciationPath" value="@Model.NamePronunciationPath"> *@
|
||||||
|
@* </div> *@
|
||||||
|
|
||||||
|
<!-- Areas of Knowledge -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="AreasOfKnowledge">Areas of Knowledge:</label>
|
||||||
|
<input type="text" class="form-control" id="AreasOfKnowledge" name="AreasOfKnowledge" value="@Model.AreasOfKnowledge">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Projects -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="Projects">Projects:</label>
|
||||||
|
<input type="text" class="form-control" id="Projects" name="Projects" value="@Model.Projects">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Team -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="Team">Team:</label>
|
||||||
|
<input type="text" class="form-control" id="Team" name="Team" value="@Model.Team">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Working Hours -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="WorkingHours">Working Hours:</label>
|
||||||
|
<input type="text" class="form-control" id="WorkingHours" name="WorkingHours" value="@Model.WorkingHours">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Time Zone -->
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="TimeZone">Time Zone:</label>
|
||||||
|
<input type="text" class="form-control" id="TimeZone" name="TimeZone" value="@Model.TimeZone">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="submit" class="btn btn-primary">Create Profile</button>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user