Insert Null values in SQL Server Table from ASP.NET-MVC app

asp.net-mvc-5 c# entity-framework-6 linq sql-server-2012

Question

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

enter image description here

error

enter image description here

Model class

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; }
}

Method To Update record

 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

Create Student Record Method

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; }
    }

enter image description here

1
0
7/29/2015 11:49:32 AM

Popular Answer

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 });
1
7/29/2015 12:13:15 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow