I am working on ASP.NET-MVC5 app and I have tables in which I need to insert null values in some of the attribute but I am getting null value exception error. I have 5 bit fields in this table which need to update invidually
public class StudentProfileStatus
{
public StudentProfileStatus() { }
[Key]
[Display(Name = "Student ID")]
public int StudentID { get; set; }
[Display(Name = "Personal Detail Status")]
public Nullable<bool> PersonalDetailStatus { get; set; }
[Display(Name = "Address Detail Status")]
public Nullable<bool> AddressDetailStatus { get; set; }
[Display(Name = "Contact Detail Status")]
public Nullable<bool> ContactDetailStatus { get; set; }
[Display(Name = "Course Detail Status")]
public Nullable<bool> CourseDetailStatus { get; set; }
[Display(Name = "Emergency Contact Detail Status")]
public Nullable<bool> EmergencyContactDetailStatus { get; set; }
public Student Student { get; set; }
}
public int UpdateStudentPersonalDetailStatus(StudentProfileStatus _studentProfileStatusModel)
{
try
{
using (var _uow = new StudentProfile_UnitOfWork())
{
_uow.StudentProfileStatus_Repository.InsertEntity(_studentProfileStatusModel);
_uow.Save();
return _studentProfileStatusModel.StudentID;
}
}
catch { return 0; }
}
Method calling another method (above) to update status if it create student record
public int CreateNewStudentProfile(Student _student)
{
try
{
using(var _uow = new StudentProfile_UnitOfWork())
{
_uow.Student_Repository.InsertEntity(_student);
_uow.Save();
if (_student.StudentID != 0 && _student.StudentID >0)
{
var studentID = UpdateStudentPersonalDetailStatus(new StudentProfileStatus {StudentID=_student.StudentID, PersonalDetailStatus = true });
}
return _student.StudentID;
}
}
catch { return 0; }
}
Put Student class as return type for _uow.Student_Repository.InsertEntity(_student)
, then try this
var data = _uow.Student_Repository.InsertEntity(_student);
var studentID = UpdateStudentPersonalDetailStatus(new StudentProfileStatus{StudentID= data.StudentID, PersonalDetailStatus = true });