Hi guys, I am fairly new to the mvc architecture. I'm basically doing an application form for loans. However, when attempting to insert data into the database, it breaks at debug and throws this exception error. Any help will be appreciated :)
This is my Model class in which the customer table and identity document table are joined.
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Template.Data;
namespace Template.Model
{
public class CustomerIdentityView
{
public int customerNumber { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public string gender { get; set; }
public DateTime dateOfBirth { get; set; }
public int age { get; set; }
public string emailAddress { get; set; }
public string businessPhoneNumber { get; set; }
public string homePhoneNumber { get; set; }
public string mobilePhoneNumber { get; set; }
public int faxNumber { get; set; }
public string address { get; set; }
public string city { get; set; }
public string province { get; set; }
public int postalCode { get; set; }
public string homeLanguage { get; set; }
public string homeStatus { get; set; }
public string maritalStatus { get; set; }
public int numberOfDependents { get; set; }
public string methodOfCommunication { get; set; }
public int trustRating { get; set; }
public virtual ICollection<LoanApplicationView> LoanApplications { get; set; }
public virtual ICollection<IdentityDocumentView> IdentityDocuments { get; set; }
public virtual ICollection<PayslipView> Payslips { get; set; }
public virtual ICollection<BankStatementView> BankStatements { get; set; }
public virtual ICollection<LoanPaymentView> LoanPayment { get; set; }
public string idNumber { get; set; }
public byte idDocument { get; set; }
public bool submissionStatus { get; set; }
public int employeeNumber { get; set; }
[ForeignKey("employeeNumber")]
public virtual Employee Employees { get; set; }
public bool IDVerificationStatus { get; set; }
public string creditCheckStatus { get; set; }
public string DateOfVerfiication { get; set; }
public int customerNumber { get; set; }
[ForeignKey("customerNumber")]
public virtual Customer Customers { get; set; }
}
}
This is my Homecontroller:
using System.Web;
using System.Web.Mvc;
using Microsoft.Owin.Security;
using Template.BusinessLogic;
using Template.Model;
using System.IO;
namespace Template.MVC5.Controllers
{
public class HomeController : Controller
{
readonly EnquiriesBusiness _Enquiry = new EnquiriesBusiness();
readonly CustomerIdentityBusiness _cib= new CustomerIdentityBusiness();
readonly PayslipBusiness _psb = new PayslipBusiness();
readonly BankStatementBusiness _bsb = new BankStatementBusiness();
private IAuthenticationManager AuthenticationManager
{
get
{
return HttpContext.GetOwinContext().Authentication;
}
}
public ActionResult Index()
{
var clinicbusiness = new ClinicBusiness();
return View(clinicbusiness.GetAllClinics());
}
public ActionResult Home()
{
var clinicbusiness = new ClinicBusiness();
return View(clinicbusiness.GetAllClinics());
}
public ActionResult Application()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Application(CustomerIdentityView model)
{
if(ModelState.IsValid)
{
_cib.AddCustomers(model);
return Redirect("~/Home/Employment");
}
return View(model);
}
public ActionResult Employment()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Employment(PayslipView model)
{
if(ModelState.IsValid)
{
_psb.AddPayslips(model);
return RedirectToAction("~/Home/Banking");
}
return View(model);
}
public ActionResult Banking()
{
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Banking(BankStatementView model)
{
if(ModelState.IsValid)
{
_bsb.AddBankStatements(model);
return RedirectToAction("~/Home/Submit");
}
return View(model);
}
public ActionResult Submit()
{
return View();
}
}
And this is my businessLogic layer for the model: CustomerIdentityView
using System.Collections.Generic;
using System.Linq;
using Microsoft.Owin.Security;
using Template.Data;
using Template.Model;
using Template.Service;
namespace Template.BusinessLogic
{
public class CustomerIdentityBusiness : ICustomerIdentityBusiness
{
public void AddCustomers(CustomerIdentityView customer)
{
var cust = new CustomerBusiness();
cust.AddCustomers(new CustomerView
{
customerNumber=customer.customerNumber,
firstName = customer.firstName,
lastName = customer.lastName,
gender = customer.gender,
age=customer.age,
dateOfBirth = customer.dateOfBirth,
emailAddress = customer.emailAddress,
businessPhoneNumber = customer.businessPhoneNumber,
homePhoneNumber = customer.homePhoneNumber,
mobilePhoneNumber = customer.mobilePhoneNumber,
faxNumber = customer.faxNumber,
address = customer.address,
city = customer.city,
province = customer.province,
postalCode = customer.postalCode,
methodOfCommunication = customer.methodOfCommunication,
homeLanguage=customer.homeLanguage,
homeStatus=customer.homeStatus,
maritalStatus=customer.maritalStatus,
numberOfDependents=customer.numberOfDependents,
trustRating=customer.trustRating
});
var id = new IdentityDocumentBusiness();
id.AddIdentityDocuments(new IdentityDocumentView
{
idNumber = customer.idNumber,
idDocument = customer.idDocument,
submissionStatus = customer.submissionStatus,
employeeNumber = customer.employeeNumber,
DateOfVerfiication = customer.DateOfVerfiication,
IDVerificationStatus = customer.IDVerificationStatus,
});
}
public IEnumerable<CustomerIdentityView> GetAll()
{
var myAppList = new List<CustomerIdentityView>();
var customerBusiness = new CustomerBusiness();
var identityDocument = new IdentityDocumentBusiness();
foreach (var c in customerBusiness.GetAllCustomers())
{
var id = identityDocument.GetIdentityDocumentsById(c.customerNumber);
var customerId = new CustomerIdentityView
{
customerNumber=c.customerNumber,
firstName = c.firstName,
lastName = c.lastName,
gender = c.gender,
dateOfBirth = c.dateOfBirth,
age=c.age,
emailAddress = c.emailAddress,
businessPhoneNumber = c.businessPhoneNumber,
homePhoneNumber = c.homePhoneNumber,
mobilePhoneNumber = c.mobilePhoneNumber,
faxNumber = c.faxNumber,
address = c.address,
city = c.city,
province = c.province,
postalCode = c.postalCode,
creditCheckStatus = id.creditCheckStatus,
methodOfCommunication = c.methodOfCommunication,
idNumber = id.idNumber,
idDocument = id.idDocument,
submissionStatus = id.submissionStatus,
employeeNumber = id.employeeNumber,
DateOfVerfiication = id.DateOfVerfiication,
IDVerificationStatus = id.IDVerificationStatus,
};
myAppList.Add(customerId);
}
return myAppList;
}
}
}