Beispiel #1
0
        public ActionResult ShowEditTeacher(long TeacherId)
        {
            List <tblTeacherCategory> TCategorylist = Connection.tblTeacherCategories.ToList();

            ViewBag.TeacherCategoryDrpDown = new SelectList(TCategorylist,
                                                            "TeacherCategoryId",
                                                            "TeacherCategoryName");

            List <tblSchool> TSlist = Connection.tblSchools.ToList();

            ViewBag.ETSchools = new SelectList(TSlist, "SchoolId", "SchoolName");

            TeacherModel TModel = new TeacherModel();

            tblTeacher TCtable = Connection.tblTeachers.SingleOrDefault(x => x.TeacherId == TeacherId);

            TModel.IsActive          = TCtable.IsActive;
            TModel.Address1          = TCtable.Address1;
            TModel.Address2          = TCtable.Address2;
            TModel.Address3          = TCtable.Address3;
            TModel.DateOfBirth       = TCtable.DateOfBirth;
            TModel.Description       = TCtable.Description;
            TModel.DrivingLicense    = TCtable.DrivingLicense;
            TModel.EmployeeNo        = TCtable.EmployeeNo;
            TModel.Gender            = TCtable.Gender;
            TModel.UserId            = TCtable.UserId;
            TModel.Name              = TCtable.Name;
            TModel.Telephone         = TCtable.Telephone;
            TModel.NIC               = TCtable.NIC;
            TModel.Passport          = TCtable.Passport;
            TModel.DrivingLicense    = TCtable.DrivingLicense;
            TModel.TeacherId         = TCtable.TeacherId;
            TModel.TeacherCategoryId = TCtable.TeacherCategoryId;

            tblTeacherSchool Tstbl = Connection.tblTeacherSchools.SingleOrDefault(
                x => x.TeacherId == TeacherId);

            TModel.SchoolID = Tstbl.SchoolId;

            return(PartialView("EditTeacherDetailsView", TModel));
        }
Beispiel #2
0
        public JsonResult EditTeacherDetails(TeacherModel Model)
        {
            string result = "Error";

            try
            {
                tblTeacher Newt = Connection.tblTeachers.SingleOrDefault(x => x.TeacherId == Model.TeacherId);
                Newt.ModifiedBy        = "ADMIN";
                Newt.ModifiedDate      = DateTime.Now;
                Newt.TeacherCategoryId = Model.TeacherCategoryId;
                Newt.DateOfBirth       = Model.DateOfBirth;
                Newt.Address1          = Model.Address1;
                Newt.Address2          = Model.Address2;
                Newt.Address3          = Model.Address3;
                Newt.Telephone         = Model.Telephone;
                Newt.Gender            = Model.Gender;
                Newt.Description       = Model.Description;
                Newt.EmployeeNo        = Model.EmployeeNo;
                Newt.DrivingLicense    = Model.DrivingLicense;
                Newt.NIC      = Model.NIC;
                Newt.Name     = Model.Name;
                Newt.Passport = Model.Passport;

                tblTeacherSchool Tstbl = Connection.tblTeacherSchools.SingleOrDefault(
                    x => x.TeacherId == Model.TeacherId);
                Tstbl.SchoolId = Model.SchoolID;

                Connection.SaveChanges();

                result = Model.TeacherId.ToString();
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Errorlog.ErrorManager.LogError("Teacher Controller @EditTeacherDetails", dbEx);
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Beispiel #3
0
        public JsonResult CreateTeacher(TeacherModel Model)
        {
            string result = "Error";

            using (SchoolMGTEntitiesConnectionString Connection = new SchoolMGTEntitiesConnectionString())
            {
                using (var scope = new TransactionScope())
                {
                    try
                    {
                        tblTeacher Newt = new tblTeacher();

                        Newt.CreatedBy         = _session.User_Id;
                        Newt.CreatedDate       = DateTime.Now;
                        Newt.TeacherCategoryId = 0;
                        Newt.TeacherCategoryId = Model.TeacherCategoryId;
                        Newt.DateOfBirth       = Model.DateOfBirth;
                        Newt.Address1          = Model.Address1;
                        Newt.Address2          = Model.Address2;
                        Newt.Address3          = Model.Address3;
                        Newt.Telephone         = Model.Telephone;
                        Newt.Gender            = Model.Gender;
                        Newt.Description       = Model.Description;
                        Newt.EmployeeNo        = Model.EmployeeNo;
                        Newt.DrivingLicense    = Model.DrivingLicense;
                        Newt.NIC      = Model.NIC;
                        Newt.Name     = Model.Name;
                        Newt.Passport = Model.Passport;
                        Newt.UserId   = Model.UserId;
                        Newt.IsActive = "Y";

                        Connection.tblTeachers.Add(Newt);
                        Connection.SaveChanges();

                        var TID = Connection.tblTeachers.Where(b => b.UserId == Model.UserId).FirstOrDefault();

                        tblTeacherSchool ts = new tblTeacherSchool();
                        ts.SchoolId          = Model.SchoolID;
                        ts.TeacherCategoryId = TID.TeacherCategoryId;
                        ts.TeacherId         = TID.TeacherId;
                        ts.CreatedBy         = _session.User_Id;
                        ts.CreatedDate       = DateTime.Now;
                        ts.IsActive          = "Y";

                        tblUser user = new tblUser();

                        string pass = Encrypt_Decrypt.Encrypt(Model.Password, Password);

                        user.PersonName     = Model.Name;
                        user.CreatedBy      = _session.User_Id;
                        user.CreatedDate    = DateTime.Now;
                        user.IsActive       = "Y";
                        user.JobDescription = "School Teacher";
                        user.LoginEmail     = Model.LoginEmail;
                        user.Mobile         = Model.Telephone;
                        user.Password       = pass;
                        user.UserCategory   = TeacherCatID;
                        user.UserId         = Model.UserId;
                        user.SchoolId       = Model.SchoolID;

                        Connection.tblUsers.Add(user);
                        Connection.tblTeacherSchools.Add(ts);

                        Connection.SaveChanges();

                        result = "Success";
                        scope.Complete();
                    }
                    catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
                    {
                        //Exception raise = dbEx;
                        //foreach (var validationErrors in dbEx.EntityValidationErrors)
                        //{
                        //    foreach (var validationError in validationErrors.ValidationErrors)
                        //    {
                        //        string message = string.Format("{0}:{1}",
                        //            validationErrors.Entry.Entity.ToString(),
                        //            validationError.ErrorMessage);
                        //        // raise a new exception nesting
                        //        // the current instance as InnerException
                        //        raise = new InvalidOperationException(message, raise);
                        //    }
                        //}
                        Errorlog.ErrorManager.LogError("public JsonResult CreateTeacher(TeacherModel Model) @TeacherController", dbEx);
                        // throw raise;
                    }
                }
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }