Skip to content

Commit 9800064

Browse files
duykhuongkidthiennn
authored andcommitted
#183 Add auto fill in User info (#188)
1 parent bf8f54f commit 9800064

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Modules/SimplCommerce.Module.Contacts/Controllers/ContactController.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Linq;
22
using Microsoft.AspNetCore.Mvc;
33
using System.Collections.Generic;
4+
using System.Threading.Tasks;
45
using SimplCommerce.Infrastructure.Data;
6+
using SimplCommerce.Module.Core.Extensions;
57
using SimplCommerce.Module.Contacts.Models;
68
using SimplCommerce.Module.Contacts.ViewModels;
79

@@ -11,21 +13,32 @@ public class ContactController : Controller
1113
{
1214
private readonly IRepository<Contact> _contactRepository;
1315
private readonly IRepository<ContactArea> _contactAreaRepository;
16+
private readonly IWorkContext _workContext;
1417

15-
public ContactController(IRepository<Contact> contactRepository, IRepository<ContactArea> contactAreaRepository)
18+
public ContactController(IRepository<Contact> contactRepository, IRepository<ContactArea> contactAreaRepository, IWorkContext workContext)
1619
{
1720
_contactRepository = contactRepository;
1821
_contactAreaRepository = contactAreaRepository;
22+
_workContext = workContext;
1923
}
2024

2125
[Route("contact")]
22-
public IActionResult Index()
26+
public async Task<IActionResult> Index()
2327
{
2428
var model = new ContactVm()
2529
{
2630
ContactAreas = GetContactArea()
2731
};
2832

33+
if(User.Identity.IsAuthenticated)
34+
{
35+
var currentUser = await _workContext.GetCurrentUser();
36+
37+
model.FullName = currentUser.FullName;
38+
model.EmailAddress = currentUser.Email;
39+
model.PhoneNumber = currentUser.PhoneNumber;
40+
}
41+
2942
return View(model);
3043
}
3144

0 commit comments

Comments
 (0)