Beispiel #1
0
        public ActionResult TutorAction(int?id)
        {
            ViewBag.drpTutorLevel = CommonController.drpTutorLevel();

            if (id != 0)
            {
                Tutor     datasetTutor = entities.Tutors.Find(id);
                User      datsetUser   = entities.Users.Find(datasetTutor.UserID);
                UserTutor dataset      = new UserTutor();
                dataset.UserID       = datsetUser.UserID;
                dataset.FirstName    = datsetUser.FirstName;
                dataset.LastName     = datsetUser.LastName;
                dataset.DOB          = datsetUser.DOB;
                dataset.Email        = datsetUser.Email;
                dataset.Phone        = datsetUser.Phone;
                dataset.Password     = datsetUser.Password;
                dataset.Address      = datsetUser.Address;
                dataset.TutorID      = datasetTutor.TutorID;
                dataset.TutorLevelID = datasetTutor.TutorLevelID;
                return(PartialView(dataset));
            }

            else
            {
                return(PartialView());
            }
        }
Beispiel #2
0
        public ActionResult TutorAction(UserTutor usertutor)
        {
            ModelState.Remove("UserID");
            ModelState.Remove("TutorID");

            if (ModelState.IsValid)
            {
                string msg = "";

                if (usertutor.TutorID > 0)
                {
                    var datasetTutor = entities.Tutors.Where(f => f.TutorID == usertutor.TutorID).FirstOrDefault();
                    var datasetUser  = entities.Users.Where(f => f.UserID == datasetTutor.UserID).FirstOrDefault();
                    if (datasetTutor != null && datasetUser != null)
                    {
                        datasetTutor.TutorLevelID = usertutor.TutorLevelID;

                        datasetUser.FirstName  = usertutor.FirstName;
                        datasetUser.LastName   = usertutor.LastName;
                        datasetUser.DOB        = usertutor.DOB;
                        datasetUser.Email      = usertutor.Email;
                        datasetUser.Phone      = usertutor.Phone;
                        datasetUser.Address    = usertutor.Address;
                        datasetUser.Password   = usertutor.Password;
                        datasetUser.UserRoleID = 3;

                        entities.SaveChanges();
                        msg = "Turor details Updated Successfully";
                    }
                }
                else
                {
                    User datasetUser = new User();
                    datasetUser.FirstName  = usertutor.FirstName;
                    datasetUser.LastName   = usertutor.LastName;
                    datasetUser.DOB        = usertutor.DOB;
                    datasetUser.Email      = usertutor.Email;
                    datasetUser.Phone      = usertutor.Phone;
                    datasetUser.Address    = usertutor.Address;
                    datasetUser.Password   = usertutor.Password;
                    datasetUser.UserRoleID = 3;
                    entities.Users.Add(datasetUser);

                    Tutor datasetTutor = new Tutor();
                    int   id           = usertutor.UserID;
                    datasetTutor.UserID       = id;
                    datasetTutor.TutorLevelID = usertutor.TutorLevelID;
                    entities.Tutors.Add(datasetTutor);
                    entities.SaveChanges();
                    msg = "New Tutor Added successfully";
                }

                return(new JsonResult
                {
                    Data = new
                    {
                        success = true,
                        action = "Tutors",
                        message = msg
                    },
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet
                });
            }
            ViewBag.drpTutorLevel = CommonController.drpTutorLevel();
            return(PartialView(usertutor));
        }