public ActionResult Create(UserViewModel model)
        {
            try
            {
                EhealthContext db = new EhealthContext();
                ViewBag.speciality_id = new SelectList(db.specialities, "id", "specialityName");

                user user = new user();
                user.username = model.username;
                user.password = model.password;
                user.role_id  = model.role_id;

                db.users.Add(user);
                db.SaveChanges();

                int latestUserId = user.id;


                doctor doctor = new doctor();
                doctor.doctorName    = model.doctorName;
                doctor.speciality_id = model.speciality_id;
                doctor.availableTime = model.availableTime;
                doctor.availableDate = model.availableDate;
                doctor.doctorContact = model.doctorContact;
                doctor.doctorEmail   = model.doctorEmail;
                doctor.user_id       = latestUserId;

                db.doctors.Add(doctor);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                throw ex;
            }

#pragma warning disable CS0162 // Unreachable code detected
            return(View(model));

#pragma warning restore CS0162 // Unreachable code detected
        }
Example #2
0
        public ActionResult Login(user user)
        {
            using (EhealthContext db = new EhealthContext())
            {
                var usr = db.users.Where(u => u.username == user.username && u.password == user.password).FirstOrDefault();
                if (usr == null)
                {
                    user.LoginErrorMessage = "Wrong Username or Password";
                    return(View("Login", user));
                }
                else
                {
                    Session["UserID"]   = usr.id;
                    Session["UserName"] = usr.username;
                    return(RedirectToAction("Index", "Login"));
                }
            }
#pragma warning disable CS0162 // Unreachable code detected
            return(View());

#pragma warning restore CS0162 // Unreachable code detected
        }