예제 #1
0
        public Boolean SaveStudent(Student student, int idSchool)
        {
            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    //var user = db.sys_user.Where(x => x.Id == student.Id).First();
                    int idParent = 0;
                    //user.Email = student.Email;
                    //user.UserName = student.UserName;

                    var sysuser = db.sys_user.Where(y => y.Id == student.Id).FirstOrDefault();
                    sysuser.active                = true;
                    sysuser.allergic              = student.allergic;
                    sysuser.blood_group           = student.blood_group;
                    sysuser.DOB                   = student.DOB;
                    sysuser.first_name            = student.first_name;
                    sysuser.gender                = student.gender;
                    sysuser.last_name             = student.last_name;
                    sysuser.middle_name           = student.middle_name;
                    sysuser.paediatrician_details = student.paediatrician_details;
                    sysuser.permanent_address     = student.permanent_address;
                    sysuser.permanent_city        = student.permanent_city;
                    sysuser.permanent_country     = student.permanent_country;
                    sysuser.permanent_state       = student.permanent_state;
                    sysuser.permanent_zip_code    = student.permanent_zip_code;
                    //sysuser.photo_url = student.photo_url;
                    sysuser.present_address  = student.present_address;
                    sysuser.present_city     = student.present_city;
                    sysuser.present_country  = student.present_country;
                    sysuser.present_state    = student.present_state;
                    sysuser.present_zip_code = student.present_zip_code;

                    var stu = db.sch_student.Where(z => z.idUser == student.Id & z.idSchool == idSchool).FirstOrDefault();
                    stu.admission_number = student.admission_number;
                    stu.admission_date   = student.admission_date;
                    stu.ts_updated       = DateTime.Now;
                    idParent             = stu.idParent;

                    var prnt = db.sch_parent.Where(x => x.idUser == idParent).FirstOrDefault();
                    //prnt.father_guardian_name = student.father_guardian_last_name + ", " + student.father_guardian_first_name;
                    prnt.father_guardian_email      = student.father_guardian_email;
                    prnt.father_guardian_occupation = student.father_guardian_occupation;
                    prnt.father_guardian_phone_no   = student.father_guardian_phone_no;
                    prnt.mother_name       = student.mother_name;
                    prnt.mother_email      = student.mother_email;
                    prnt.mother_phone_no   = student.mother_phone_no;
                    prnt.mother_occupation = student.mother_occupation;
                    prnt.ts_updated        = DateTime.Now;

                    db.SaveChanges();
                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    return(false);
                }
            }
            return(true);
        }
예제 #2
0
        public Boolean Addstudent(Student student, int idSchool)
        {
            using (var transaction = db.Database.BeginTransaction())
            {
                try
                {
                    string strUserName     = student.first_name.Substring(0, 1).ToLower() + "" + student.last_name.Substring(0, 1).ToLower();
                    string strStudentEmail = "";
                    if (student.Email != null)
                    {
                        strStudentEmail = student.Email;
                    }
                    else
                    {
                        strStudentEmail = student.first_name.ToLower() + "." + student.last_name.ToLower() + "@schoolorbit.com";
                    }
                    string strDisplayName = "";
                    if (student.screen_name != null)
                    {
                        strDisplayName = student.screen_name;
                    }
                    else
                    {
                        strDisplayName = student.first_name + " " + student.last_name;
                    }
                    string strParentEmail    = "";
                    string strParentUserName = student.father_guardian_phone_no;
                    if (student.father_guardian_email != null)
                    {
                        strParentEmail = student.father_guardian_email;
                    }
                    else
                    {
                        strParentEmail = student.father_guardian_first_name.ToLower() + "." + student.father_guardian_last_name + "@schoolorbit.com";
                    }

                    DataModel.sys_user useraccnt = new DataModel.sys_user();
                    useraccnt.active                = true;
                    useraccnt.allergic              = student.allergic;
                    useraccnt.blood_group           = student.blood_group;
                    useraccnt.DOB                   = student.DOB;
                    useraccnt.first_name            = student.first_name;
                    useraccnt.gender                = student.gender;
                    useraccnt.last_name             = student.last_name;
                    useraccnt.middle_name           = student.middle_name;
                    useraccnt.paediatrician_details = student.paediatrician_details;
                    useraccnt.permanent_address     = student.permanent_address;
                    useraccnt.permanent_city        = student.permanent_city;
                    useraccnt.permanent_country     = student.permanent_country;
                    useraccnt.permanent_state       = student.permanent_state;
                    useraccnt.permanent_zip_code    = student.permanent_zip_code;
                    useraccnt.photo_url             = "/pictures/default-avatar.png";
                    useraccnt.present_address       = student.present_address;
                    useraccnt.present_city          = student.present_city;
                    useraccnt.present_country       = student.present_country;
                    useraccnt.present_state         = student.present_state;
                    useraccnt.present_zip_code      = student.present_zip_code;
                    useraccnt.screen_name           = strDisplayName;
                    db.sys_user.Add(useraccnt);
                    db.SaveChanges();
                    //Create Login for Student
                    UserLogin Login = new UserLogin();
                    strUserName = strUserName + useraccnt.Id;
                    var res = Login.CreateUser(useraccnt.Id, UserLogin.LoginUserType.student, strStudentEmail, strUserName);


                    //check parent already exists
                    var xuser = db.sch_parent.Where(x => x.father_guardian_email == student.father_guardian_email).FirstOrDefault();
                    DataModel.sys_user prntuseraccnt = new DataModel.sys_user();
                    if (xuser == null)
                    {
                        prntuseraccnt.active             = true;
                        prntuseraccnt.DOB                = Convert.ToDateTime("1900/01/01");
                        prntuseraccnt.first_name         = student.father_guardian_first_name;
                        prntuseraccnt.gender             = "M";
                        prntuseraccnt.last_name          = student.father_guardian_last_name;
                        prntuseraccnt.permanent_address  = student.permanent_address;
                        prntuseraccnt.permanent_city     = student.permanent_city;
                        prntuseraccnt.permanent_country  = student.permanent_country;
                        prntuseraccnt.permanent_state    = student.permanent_state;
                        prntuseraccnt.permanent_zip_code = student.permanent_zip_code;
                        prntuseraccnt.photo_url          = "/pictures/default-avatar.png";
                        prntuseraccnt.present_address    = student.present_address;
                        prntuseraccnt.present_city       = student.present_city;
                        prntuseraccnt.present_country    = student.present_country;
                        prntuseraccnt.present_state      = student.present_state;
                        prntuseraccnt.present_zip_code   = student.present_zip_code;
                        prntuseraccnt.screen_name        = student.father_guardian_first_name + " " + student.father_guardian_last_name;
                        db.sys_user.Add(prntuseraccnt);
                        db.SaveChanges();


                        //Create Login for Parent
                        UserLogin ParentLogin = new UserLogin();
                        var       result      = ParentLogin.CreateUser(prntuseraccnt.Id, UserLogin.LoginUserType.parent, strParentEmail, strParentUserName);

                        DataModel.sch_parent prnt = new DataModel.sch_parent();
                        prnt.idUser = prntuseraccnt.Id;
                        prnt.father_guardian_email      = student.father_guardian_email;
                        prnt.father_guardian_name       = student.father_guardian_first_name;
                        prnt.father_guardian_occupation = student.father_guardian_occupation;
                        prnt.father_guardian_phone_no   = student.father_guardian_phone_no;
                        prnt.mother_name       = student.mother_name;
                        prnt.mother_email      = student.mother_email;
                        prnt.mother_phone_no   = student.mother_phone_no;
                        prnt.mother_occupation = student.mother_occupation;
                        prnt.ts_entered        = DateTime.Now;
                        prnt.ts_updated        = DateTime.Now;
                        db.sch_parent.Add(prnt);
                        db.SaveChanges();
                    }

                    //link parent id to student
                    DataModel.sch_student stud = new DataModel.sch_student();
                    stud.admission_date = student.admission_date;
                    // Need to put Validation for Duplicate Admission Numbers..
                    stud.admission_number = student.admission_number;
                    // End
                    // School Id should come Roles
                    stud.idSchool = idSchool;
                    // end
                    stud.idUser    = useraccnt.Id;
                    stud.is_active = true;
                    if (xuser == null)
                    {
                        stud.idParent = prntuseraccnt.Id;
                    }
                    else
                    {
                        stud.idParent = xuser.idUser;
                    }
                    stud.ts_entered = DateTime.Now;
                    stud.ts_updated = DateTime.Now;
                    db.sch_student.Add(stud);
                    db.SaveChanges();
                    transaction.Commit();
                    return(true);
                }

                catch (Exception Ex)
                {
                    transaction.Rollback();
                    return(false);

                    throw Ex;
                }
            }
        }