Skip to content

Commit 327eb93

Browse files
duykhuongkidthiennn
authored andcommitted
Contact (#183)
* 177 Add Contact Category * 89 add Contact Us page * 89 Change Contact category to Contact Area * #89 Add Contact list view in Admin page * correct rebase * clean code * add GoogleAppKey config
1 parent a7b16fd commit 327eb93

38 files changed

+2928
-165
lines changed

SimplCommerce.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimplCommerce.Module.Cms.Te
5252
EndProject
5353
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimplCommerce.Module.ProductComparison", "src\Modules\SimplCommerce.Module.ProductComparison\SimplCommerce.Module.ProductComparison.csproj", "{3BA470E8-1A8A-4E36-A1AE-669838816770}"
5454
EndProject
55+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimplCommerce.Module.Contacts", "src\Modules\SimplCommerce.Module.Contacts\SimplCommerce.Module.Contacts.csproj", "{EA8A1804-7807-4CC5-9412-CF835BEAFC06}"
56+
EndProject
5557
Global
5658
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5759
Debug|Any CPU = Debug|Any CPU
@@ -266,6 +268,18 @@ Global
266268
{3BA470E8-1A8A-4E36-A1AE-669838816770}.Release|x64.Build.0 = Release|Any CPU
267269
{3BA470E8-1A8A-4E36-A1AE-669838816770}.Release|x86.ActiveCfg = Release|Any CPU
268270
{3BA470E8-1A8A-4E36-A1AE-669838816770}.Release|x86.Build.0 = Release|Any CPU
271+
{EA8A1804-7807-4CC5-9412-CF835BEAFC06}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
272+
{EA8A1804-7807-4CC5-9412-CF835BEAFC06}.Debug|Any CPU.Build.0 = Debug|Any CPU
273+
{EA8A1804-7807-4CC5-9412-CF835BEAFC06}.Debug|x64.ActiveCfg = Debug|Any CPU
274+
{EA8A1804-7807-4CC5-9412-CF835BEAFC06}.Debug|x64.Build.0 = Debug|Any CPU
275+
{EA8A1804-7807-4CC5-9412-CF835BEAFC06}.Debug|x86.ActiveCfg = Debug|Any CPU
276+
{EA8A1804-7807-4CC5-9412-CF835BEAFC06}.Debug|x86.Build.0 = Debug|Any CPU
277+
{EA8A1804-7807-4CC5-9412-CF835BEAFC06}.Release|Any CPU.ActiveCfg = Release|Any CPU
278+
{EA8A1804-7807-4CC5-9412-CF835BEAFC06}.Release|Any CPU.Build.0 = Release|Any CPU
279+
{EA8A1804-7807-4CC5-9412-CF835BEAFC06}.Release|x64.ActiveCfg = Release|Any CPU
280+
{EA8A1804-7807-4CC5-9412-CF835BEAFC06}.Release|x64.Build.0 = Release|Any CPU
281+
{EA8A1804-7807-4CC5-9412-CF835BEAFC06}.Release|x86.ActiveCfg = Release|Any CPU
282+
{EA8A1804-7807-4CC5-9412-CF835BEAFC06}.Release|x86.Build.0 = Release|Any CPU
269283
EndGlobalSection
270284
GlobalSection(SolutionProperties) = preSolution
271285
HideSolutionNode = FALSE
@@ -290,5 +304,6 @@ Global
290304
{4FE8CC2E-3DF9-4AE7-A04E-4293FABEE221} = {7EFA2FA7-32DD-4047-B021-50E77A83D714}
291305
{483C5E8D-99A4-410D-8DB3-2F695B05BF40} = {D9FD9ABA-AE5E-4427-AA6B-6285BE2E212D}
292306
{3BA470E8-1A8A-4E36-A1AE-669838816770} = {7EFA2FA7-32DD-4047-B021-50E77A83D714}
307+
{EA8A1804-7807-4CC5-9412-CF835BEAFC06} = {7EFA2FA7-32DD-4047-B021-50E77A83D714}
293308
EndGlobalSection
294309
EndGlobal

src/Database/StaticData.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
INSERT [dbo].[Core_AppSetting] ([Id], [Key], [Value]) VALUES (1, N'Catalog.ProductPageSize', N'10')
33
INSERT [dbo].[Core_AppSetting] ([Id], [Key], [Value]) VALUES (2, N'Global.AssetVersion', N'1.0')
44
INSERT [dbo].[Core_AppSetting] ([Id], [Key], [Value]) VALUES (3, N'News.PageSize', N'10')
5+
INSERT [dbo].[Core_AppSetting] ([Id], [Key], [Value]) VALUES (4, N'GoogleAppKey', N'AIzaSyBmsQV2FUo6g52R1kovLyfvaYm4FryNs4g')
56
SET IDENTITY_INSERT [dbo].[Core_AppSetting] OFF
67
GO
78

src/Database/StaticData_Postgres.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
INSERT INTO "Core_AppSetting" ("Id", "Key", "Value") VALUES (1, 'Catalog.ProductPageSize', '10');
22
INSERT INTO "Core_AppSetting" ("Id", "Key", "Value") VALUES (2, 'Global.AssetVersion', '1.0');
33
INSERT INTO "Core_AppSetting" ("Id", "Key", "Value") VALUES (3, 'News.PageSize', '10');
4-
SELECT pg_catalog.setval('"Core_AppSetting_Id_seq"', 3, true);
4+
INSERT INTO "Core_AppSetting" ("Id", "Key", "Value") VALUES (4, 'GoogleAppKey', 'AIzaSyBmsQV2FUo6g52R1kovLyfvaYm4FryNs4g');
5+
SELECT pg_catalog.setval('"Core_AppSetting_Id_seq"', 4, true);
56

67
INSERT INTO "Core_Role" ("Id", "ConcurrencyStamp", "Name", "NormalizedName") VALUES (1, 'bd3bee0b-5f1d-482d-b890-ffdc01915da3', 'admin', 'ADMIN');
78
INSERT INTO "Core_Role" ("Id", "ConcurrencyStamp", "Name", "NormalizedName") VALUES (2, 'bd3bee0b-5f1d-482d-b890-ffdc01915da3', 'customer', 'CUSTOMER');
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
using System;
2+
using System.Linq;
3+
using Microsoft.AspNetCore.Authorization;
4+
using Microsoft.AspNetCore.Mvc;
5+
using Microsoft.EntityFrameworkCore;
6+
using SimplCommerce.Infrastructure.Data;
7+
using SimplCommerce.Module.Contacts.Models;
8+
using SimplCommerce.Module.Core.Extensions;
9+
using SimplCommerce.Module.Core.Services;
10+
using SimplCommerce.Module.Contacts.ViewModels;
11+
using SimplCommerce.Infrastructure.Web.SmartTable;
12+
13+
namespace SimplCommerce.Module.Contacts.Controllers
14+
{
15+
[Authorize(Roles = "admin")]
16+
[Route("api/contacts")]
17+
public class ContactApiController : Controller
18+
{
19+
private readonly IRepository<Contact> _contactRepository;
20+
private readonly IMediaService _mediaService;
21+
private readonly IWorkContext _workContext;
22+
23+
public ContactApiController(IRepository<Contact> contactRepository, IMediaService mediaService, IWorkContext workContext)
24+
{
25+
_contactRepository = contactRepository;
26+
_mediaService = mediaService;
27+
_workContext = workContext;
28+
}
29+
30+
[HttpPost("grid")]
31+
public IActionResult Get([FromBody] SmartTableParam param)
32+
{
33+
var query = _contactRepository.Query()
34+
.Include(x => x.ContactArea)
35+
.Where(x => !x.IsDeleted);
36+
37+
if (param.Search.PredicateObject != null)
38+
{
39+
dynamic search = param.Search.PredicateObject;
40+
41+
if (search.FullName != null)
42+
{
43+
string name = search.FullName;
44+
query = query.Where(x => x.FullName.Contains(name));
45+
}
46+
47+
if (search.ContactAreaId != null)
48+
{
49+
long id = search.ContactAreaId;
50+
query = query.Where(x => x.ContactArea.Id == id);
51+
}
52+
53+
if (search.CreatedOn != null)
54+
{
55+
if (search.CreatedOn.before != null)
56+
{
57+
DateTimeOffset before = search.CreatedOn.before;
58+
query = query.Where(x => x.CreatedOn <= before);
59+
}
60+
61+
if (search.CreatedOn.after != null)
62+
{
63+
DateTimeOffset after = search.CreatedOn.after;
64+
query = query.Where(x => x.CreatedOn >= after);
65+
}
66+
}
67+
}
68+
69+
var contacts = query.ToSmartTableResult(
70+
param,
71+
x => new
72+
{
73+
Id = x.Id,
74+
FullName = x.FullName,
75+
ContactArea = x.ContactArea.Name,
76+
CreatedOn = x.CreatedOn,
77+
Content = x.Content
78+
});
79+
return Json(contacts);
80+
}
81+
82+
[HttpGet("{id}")]
83+
public IActionResult Get(long id)
84+
{
85+
var contact = _contactRepository.Query()
86+
.Include(x => x.ContactArea)
87+
.FirstOrDefault(x => x.Id == id);
88+
89+
var model = new ContactForm()
90+
{
91+
FullName = contact.FullName,
92+
PhoneNumber = contact.PhoneNumber,
93+
EmailAddress = contact.EmailAddress,
94+
Address = contact.Address,
95+
Content = contact.Content,
96+
CreatedOn = contact.CreatedOn,
97+
ContactArea = contact.ContactArea.Name
98+
};
99+
100+
return Json(model);
101+
}
102+
103+
[HttpDelete("{id}")]
104+
public IActionResult Delete(long id)
105+
{
106+
var contact = _contactRepository.Query().FirstOrDefault(x => x.Id == id);
107+
108+
if (contact == null)
109+
{
110+
return NotFound();
111+
}
112+
113+
contact.IsDeleted = true;
114+
_contactRepository.SaveChange();
115+
116+
return Ok();
117+
}
118+
}
119+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
using System.Linq;
2+
using Microsoft.AspNetCore.Authorization;
3+
using Microsoft.AspNetCore.Mvc;
4+
using SimplCommerce.Infrastructure.Data;
5+
using SimplCommerce.Module.Contacts.Models;
6+
using SimplCommerce.Module.Contacts.ViewModels;
7+
8+
namespace SimplCommerce.Module.Contacts.Controllers
9+
{
10+
[Authorize(Roles = "admin")]
11+
[Route("api/contact-area")]
12+
public class ContactAreaApiController : Controller
13+
{
14+
private readonly IRepository<ContactArea> _contactRepository;
15+
16+
public ContactAreaApiController(IRepository<ContactArea> categoryRepository)
17+
{
18+
_contactRepository = categoryRepository;
19+
}
20+
21+
public IActionResult Get()
22+
{
23+
var categoryList = _contactRepository.Query().Where(x => !x.IsDeleted).ToList();
24+
return Json(categoryList);
25+
}
26+
27+
[HttpGet("{id}")]
28+
public IActionResult Get(long id)
29+
{
30+
var category = _contactRepository.Query().FirstOrDefault(x => x.Id == id);
31+
var model = new ContactAreaForm
32+
{
33+
Id = category.Id,
34+
Name = category.Name
35+
};
36+
37+
return Json(model);
38+
}
39+
40+
[HttpPost]
41+
public IActionResult Post([FromBody] ContactAreaForm model)
42+
{
43+
if (ModelState.IsValid)
44+
{
45+
var category = new ContactArea
46+
{
47+
Name = model.Name
48+
};
49+
50+
_contactRepository.Add(category);
51+
_contactRepository.SaveChange();
52+
53+
return Ok();
54+
}
55+
return new BadRequestObjectResult(ModelState);
56+
}
57+
58+
[HttpPut("{id}")]
59+
public IActionResult Put(long id, [FromBody] ContactAreaForm model)
60+
{
61+
if (ModelState.IsValid)
62+
{
63+
var category = _contactRepository.Query().FirstOrDefault(x => x.Id == id);
64+
category.Name = model.Name;
65+
66+
_contactRepository.SaveChange();
67+
68+
return Ok();
69+
}
70+
71+
return new BadRequestObjectResult(ModelState);
72+
}
73+
74+
[HttpDelete("{id}")]
75+
public IActionResult Delete(long id)
76+
{
77+
var category = _contactRepository.Query().FirstOrDefault(x => x.Id == id);
78+
if (category == null)
79+
{
80+
return new NotFoundResult();
81+
}
82+
83+
category.IsDeleted = true;
84+
_contactRepository.SaveChange();
85+
86+
return Json(true);
87+
}
88+
}
89+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Linq;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System.Collections.Generic;
4+
using SimplCommerce.Infrastructure.Data;
5+
using SimplCommerce.Module.Contacts.Models;
6+
using SimplCommerce.Module.Contacts.ViewModels;
7+
8+
namespace SimplCommerce.Module.Contacts.Controllers
9+
{
10+
public class ContactController : Controller
11+
{
12+
private readonly IRepository<Contact> _contactRepository;
13+
private readonly IRepository<ContactArea> _contactAreaRepository;
14+
15+
public ContactController(IRepository<Contact> contactRepository, IRepository<ContactArea> contactAreaRepository)
16+
{
17+
_contactRepository = contactRepository;
18+
_contactAreaRepository = contactAreaRepository;
19+
}
20+
21+
[Route("contact")]
22+
public IActionResult Index()
23+
{
24+
var model = new ContactVm()
25+
{
26+
ContactAreas = GetContactArea()
27+
};
28+
29+
return View(model);
30+
}
31+
32+
[Route("contact")]
33+
[HttpPost]
34+
public IActionResult SubmitContact(ContactVm model)
35+
{
36+
if (ModelState.IsValid)
37+
{
38+
var contact = new Models.Contact()
39+
{
40+
FullName = model.FullName,
41+
PhoneNumber = model.PhoneNumber,
42+
EmailAddress = model.EmailAddress,
43+
Address = model.Address,
44+
ContactAreaId = model.ContactAreaId,
45+
Content = model.Content
46+
};
47+
48+
_contactRepository.Add(contact);
49+
_contactRepository.SaveChange();
50+
51+
return View("SubmitContactResult", model);
52+
}
53+
54+
model.ContactAreas = GetContactArea();
55+
56+
return View("Index", model);
57+
}
58+
59+
private IList<ContactAreaVm> GetContactArea()
60+
{
61+
var categories = _contactAreaRepository.Query()
62+
.Where(x => !x.IsDeleted)
63+
.Select(x => new ContactAreaVm()
64+
{
65+
Id = x.Id,
66+
Name = x.Name
67+
}).ToList();
68+
69+
return categories;
70+
}
71+
}
72+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using SimplCommerce.Infrastructure.Models;
3+
4+
namespace SimplCommerce.Module.Contacts.Models
5+
{
6+
public class Contact : EntityBase
7+
{
8+
public Contact()
9+
{
10+
CreatedOn = DateTimeOffset.Now;
11+
}
12+
13+
public string FullName { get; set; }
14+
15+
public string PhoneNumber { get; set; }
16+
17+
public string EmailAddress { get; set; }
18+
19+
public string Address { get; set; }
20+
21+
public string Content { get; set; }
22+
23+
public long ContactAreaId { get; set; }
24+
25+
public virtual ContactArea ContactArea { get; set; }
26+
27+
public bool IsDeleted { get; set; }
28+
29+
public DateTimeOffset CreatedOn { get; set; }
30+
}
31+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using SimplCommerce.Infrastructure.Models;
2+
3+
namespace SimplCommerce.Module.Contacts.Models
4+
{
5+
public class ContactArea : EntityBase
6+
{
7+
public string Name { get; set; }
8+
9+
public bool IsDeleted { get; set; }
10+
}
11+
}

0 commit comments

Comments
 (0)