Skip to content

Commit

Permalink
New form for shipping address is added to profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
Rostech committed Oct 4, 2022
1 parent aafda08 commit 1acdefc
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 18 deletions.
5 changes: 5 additions & 0 deletions src/DevBetterWeb.Core/ValueObjects/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ public string ToCityStateCountryString()

return string.Join(',', tokens);
}

public override string ToString()
{
return $"{this.Street}, {this.City}, {this.State} {this.PostalCode}, {this.Country}";
}
}
1 change: 1 addition & 0 deletions src/DevBetterWeb.Web/DevBetterWeb.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<PackageReference Include="CSharpFunctionalExtensions" Version="2.34.0"/>
<PackageReference Include="Dapper" Version="2.0.123"/>
<PackageReference Include="GoogleReCaptcha.V3" Version="1.3.1"/>
<PackageReference Include="ISO3166" Version="1.0.4" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.8"/>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.3.0"/>
Expand Down
47 changes: 38 additions & 9 deletions src/DevBetterWeb.Web/Pages/User/MyProfile/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,33 @@
</div>
<br />

<div class="card">
<div class="card-header">
<b>Shipping Address</b>
</div>

<div class="card-body">
@if (@Model.UserProfileViewModel.Address != "none")
{
<div>
<strong>
@Model.UserProfileViewModel.Address
</strong>
</div>
}

<span class="text-secondary small">
City, State (optional), and Country are used for <a href="https://devbetter.com/user/map/60b5123e-5392-4b9a-b3bc-fd4a215d4252">map</a> location.
<br />
Full shipping address is only visible to admins and is used for shipping books and other packages to members from time to time.
</span>
</div>
<div class="card-body">
<a class="btn btn-primary nav-item" href="/User/MyProfile/ShippingAddress">Edit</a>
</div>
</div>
<br />

<div class="card">
<div class="card-header">
<b>Books You've Read</b>
Expand Down Expand Up @@ -95,8 +122,10 @@
}
else
{
<div class="card-body">You haven't added any books yet. Alumni members can add one book to the devBetter reading list.
Add one below!</div>
<div class="card-body">
You haven't added any books yet. Alumni members can add one book to the devBetter reading list.
Add one below!
</div>
<div class="card-body">
<a class="btn btn-primary nav-item" href="/User/MyProfile/BooksAdd">Add</a>
</div>
Expand Down Expand Up @@ -153,13 +182,13 @@
</div>
<br />

<div class="card">
<div class="card-header">
<b>Billing Information</b>
</div>
<div class="card-body">
<a class="btn btn-primary nav-item" href="/User/MyProfile/Billing">View</a>
</div>
<div class="card">
<div class="card-header">
<b>Billing Information</b>
</div>
<div class="card-body">
<a class="btn btn-primary nav-item" href="/User/MyProfile/Billing">View</a>
</div>
</div>
</div>
</div>
8 changes: 0 additions & 8 deletions src/DevBetterWeb.Web/Pages/User/MyProfile/Personal.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@
<span asp-validation-for="UserPersonalUpdateModel.LastName" class="text-danger"></span>
</div>

<div class="form-group">
<label class="font-weight-bold">Shipping Address</label>
<span class="text-secondary small">Only administrators can view this information - include country if
non-US</span>
<textarea asp-for="UserPersonalUpdateModel.Address" rows="5" style="max-width: 100%"
class="form-control form-control-sm">@Model.UserPersonalUpdateModel.Address</textarea>
</div>

<div class="form-group">
<label class="font-weight-bold">Birthday</label>
<p class="text-secondary small mb-1">If set, birthday will be visible to other devBetter members and may be used to celebrate your day via Discord, coaching sessions, etc.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public async Task OnPost()
member.UpdateName(UserPersonalUpdateModel.FirstName, UserPersonalUpdateModel.LastName);
member.UpdatePEInfo(UserPersonalUpdateModel.PEFriendCode, UserPersonalUpdateModel.PEUsername);
member.UpdateAboutInfo(UserPersonalUpdateModel.AboutInfo);
member.UpdateAddress(UserPersonalUpdateModel.Address);
member.UpdateBirthday(UserPersonalUpdateModel.BirthdayDay, UserPersonalUpdateModel.BirthdayMonth);
member.UpdateDiscord(UserPersonalUpdateModel.DiscordUsername);
member.UpdateEmail(UserPersonalUpdateModel.Email);
Expand Down
66 changes: 66 additions & 0 deletions src/DevBetterWeb.Web/Pages/User/MyProfile/ShippingAddress.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
@page
@using System.Linq;
@model DevBetterWeb.Web.Pages.User.ShippingAddressModel
@{
ViewData["Title"] = "My Profile: Shipping Address";
}

<h3>@ViewData["Title"]</h3>

<form method="post">
<div class="row">
<div class="col-7">
<div class="card">
<div class="card-header">
<b>Shipping Address</b>
</div>
<div class="card-body">

<div class="form-group">
<label class="font-weight-bold">Country</label>
<select asp-for="UserShippingAddressUpdateModel.Country" asp-items="@ISO3166.Country.List.Select(i => new SelectListItem { Text = i.Name, Value = i.Name }).ToList()"
class="form-control form-control-sm"></select>
<span asp-validation-for="UserShippingAddressUpdateModel.Country" class="text-danger"></span>
</div>

<div class="form-group">
<label class="font-weight-bold">City</label>
<input asp-for="UserShippingAddressUpdateModel.City" type="text" value="@Model.UserShippingAddressUpdateModel.City"
class="form-control form-control-sm" />
<span asp-validation-for="UserShippingAddressUpdateModel.City" class="text-danger"></span>
</div>

<div class="form-group">
<label class="font-weight-bold">Street</label>
<input asp-for="UserShippingAddressUpdateModel.Street" type="text" value="@Model.UserShippingAddressUpdateModel.Street"
class="form-control form-control-sm" />
<span asp-validation-for="UserShippingAddressUpdateModel.Street" class="text-danger"></span>
</div>

<div class="form-group">
<label class="font-weight-bold">Postal code</label>
<input asp-for="UserShippingAddressUpdateModel.PostalCode" type="text" value="@Model.UserShippingAddressUpdateModel.PostalCode"
class="form-control form-control-sm" />
<span asp-validation-for="UserShippingAddressUpdateModel.PostalCode" class="text-danger"></span>
</div>

<div class="form-group">
<label class="font-weight-bold">State</label>
<input asp-for="UserShippingAddressUpdateModel.State" type="text" value="@Model.UserShippingAddressUpdateModel.State"
class="form-control form-control-sm" />
<span asp-validation-for="UserShippingAddressUpdateModel.State" class="text-danger"></span>
</div>
</div>
</div>
</div>
</div>

<br />
<input type="submit" value="Save" class="btn btn-success" />
<br />
<br />

<a class="btn btn-primary nav-item" href="./">Back to My Profile</a>


</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Threading.Tasks;
using DevBetterWeb.Core;
using DevBetterWeb.Core.Entities;
using DevBetterWeb.Core.Exceptions;
using DevBetterWeb.Core.Interfaces;
using DevBetterWeb.Core.Specs;
using DevBetterWeb.Core.ValueObjects;
using DevBetterWeb.Infrastructure.Identity.Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace DevBetterWeb.Web.Pages.User
{
[Authorize(Roles = AuthConstants.Roles.ADMINISTRATORS_MEMBERS_ALUMNI)]
public class ShippingAddressModel : PageModel
{
private readonly UserManager<ApplicationUser> _userManager;
private readonly IMemberRegistrationService _memberRegistrationService;
private readonly IRepository<Member> _memberRepository;

public ShippingAddressModel(UserManager<ApplicationUser> userManager,
IMemberRegistrationService memberRegistrationService,
IRepository<Member> memberRepository)
{
_userManager = userManager;
_memberRegistrationService = memberRegistrationService;
_memberRepository = memberRepository;
}

[BindProperty]
public UserShippingAddressUpdateModel UserShippingAddressUpdateModel { get; set; }

public async Task OnGetAsync()
{
var currentUserName = User.Identity!.Name;
var applicationUser = await _userManager.FindByNameAsync(currentUserName);

var spec = new MemberByUserIdSpec(applicationUser.Id);
var member = await _memberRepository.FirstOrDefaultAsync(spec);

if (member == null)
{
member = await _memberRegistrationService.RegisterMemberAsync(applicationUser.Id);
}

UserShippingAddressUpdateModel = new UserShippingAddressUpdateModel(member);
}

public async Task OnPost()
{
if (!ModelState.IsValid) return;

var currentUserName = User.Identity!.Name;
var applicationUser = await _userManager.FindByNameAsync(currentUserName);

var spec = new MemberByUserIdSpec(applicationUser.Id);
var member = await _memberRepository.FirstOrDefaultAsync(spec);
if (member is null) throw new MemberNotFoundException(applicationUser.Id);

member.UpdateShippingAddress(new Address(UserShippingAddressUpdateModel.Street,
UserShippingAddressUpdateModel.City,
UserShippingAddressUpdateModel.State,
UserShippingAddressUpdateModel.PostalCode,
UserShippingAddressUpdateModel.Country));

member.UpdateAddress(member.ShippingAddress.ToString());

await _memberRepository.UpdateAsync(member);
}
}
}
32 changes: 32 additions & 0 deletions src/DevBetterWeb.Web/Pages/User/UserShippingAddressUpdateModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.ComponentModel.DataAnnotations;
using DevBetterWeb.Core.Entities;

namespace DevBetterWeb.Web.Pages.User;

public class UserShippingAddressUpdateModel
{
public UserShippingAddressUpdateModel()
{
}

public UserShippingAddressUpdateModel(Member member)
{
this.Street = member.ShippingAddress.Street;
this.City = member.ShippingAddress.City;
this.State = member.ShippingAddress.State;
this.PostalCode = member.ShippingAddress.PostalCode;
this.Country = member.ShippingAddress.Country;
}

[Required]
public string City { get; set; }

[Required]
public string Country { get; set; }

public string State { get; set; }
public string Street { get; set; }

public string PostalCode { get; set; }

}

0 comments on commit 1acdefc

Please sign in to comment.