Idea of the project: if someone wants to order a project development, here you can send an application.
using ProjectRequestTest.Core.Enums;
using ProjectRequestTest.Core;
using ProjectRequestTest.Web.Core;
using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
namespace ProjectRequestTest.Web
{
public partial class CreateRequest : BasePage
{
private readonly ProjectRequestItem _requestItem = new ProjectRequestItem();
private readonly ProjectRequestService _requestService;
public List<string> ErrorsList = new List<string>();
public CreateRequest()
{
_requestService = new ProjectRequestService();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillProjectTypes();
}
}
private void FillProjectTypes()
{
foreach (ProjectType type in Enum.GetValues(typeof(ProjectType)))
{
cbxProjectType.Items.Add(new ListItem(type.ToString(), type.ToString()));
}
}
private void GetFormData()
{
_requestItem.ClientName = txtClientName.Value.Trim();
_requestItem.Email = txtEmail.Value.Trim();
_requestItem.PhoneNumber = txtPhoneNumber.Value.Trim();
_requestItem.ProjectType = EnumHelper<ProjectType>.Parse(cbxProjectType.Value);
_requestItem.Description = txtDescription.Value.Trim();
}
private bool ValidatePage()
{
if (string.IsNullOrWhiteSpace(_requestItem.ClientName))
ErrorsList.Add("Field 'Your name' is required.");
if (string.IsNullOrWhiteSpace(_requestItem.Email))
ErrorsList.Add("Field 'Email' is required.");
else if (!Helpers.ValidateEmail(_requestItem.Email))
ErrorsList.Add("Wrong email format.");
if (string.IsNullOrWhiteSpace(_requestItem.PhoneNumber))
ErrorsList.Add("Field 'Phone number' is required.");
return ErrorsList.Count == 0;
}
public void btnSend_Click(object s, EventArgs e)
{
GetFormData();
if (ValidatePage())
{
_requestItem.Identifier = Helpers.GenerateNumericCode();
var newId = _requestService.Create(_requestItem);
if (newId > 0)
{
Response.Redirect($"GeneratePDF.ashx?id={_requestItem.Identifier}");
}
}
}
}
}