示例#1
0
        //account page
        public ActionResult account()
        {
            //send all specialities to account page
            ViewBag.specialities = db.specialities.getSpecialityDataList().ToList();
            //send all cities to account page
            ViewBag.cities = db.cities.getCityDataList().ToList();
            //get the current doctor
            doctor oldDoctor = db.doctors.Single(doc => doc.username == User.Identity.Name);
            //get the account page data
            doctorAccountData currentDoctor = new doctorAccountData();

            currentDoctor.username    = oldDoctor.username;
            currentDoctor.bookingType = oldDoctor.bookingType;
            currentDoctor.cityID      = db.destricts.FirstOrDefault(d => d.id == oldDoctor.destrictID).cityID;
            currentDoctor.destrictID  = oldDoctor.destrictID;
            currentDoctor.mail        = oldDoctor.mail;
            currentDoctor.password    = oldDoctor.password;
            currentDoctor.phone       = oldDoctor.phone;
            currentDoctor.proImage    = oldDoctor.proImage;
            if (oldDoctor.specialities.First().superSpecialityID != null)
            {//doctor has sub specialities
                currentDoctor.spID    = (byte)oldDoctor.specialities.First().superSpecialityID;
                currentDoctor.subSpID = oldDoctor.specialities.Select(s => s.id.ToString()).ToList();
            }
            else
            {//doctor has main speciality and not subspeciality
                currentDoctor.spID    = oldDoctor.specialities.First().id;
                currentDoctor.subSpID = new List <string>();
            }
            return(View(currentDoctor));
        }
示例#2
0
        //update account page data
        public ActionResult account(doctorAccountData updatedDoctor)
        {
            //send all specialities to account page
            ViewBag.specialities = db.specialities.getSpecialityDataList().ToList();
            //send all cities to account page
            ViewBag.cities = db.cities.getCityDataList().ToList();
            doctor oldDoctor   = getCurrentDoctor();
            string oldpassword = oldDoctor.password;
            string oldusername = oldDoctor.username;

            if (ModelState.IsValid)
            {
                try
                {
                    string newImageName = oldDoctor.proImage;
                    //check if image is valid
                    if (validateProfessionImage(oldDoctor.id.ToString(), ref newImageName, oldDoctor.proImage))
                    {
                        oldDoctor.proImage = newImageName;
                    }
                    else
                    {//image is not valid ,then image will not be updated
                        ModelState.AddModelError("proImage", Resource1.professionImgNotUpdated);
                        return(View(updatedDoctor));
                    }//update all data
                    oldDoctor.bookingType = updatedDoctor.bookingType;
                    oldDoctor.mail        = updatedDoctor.mail;
                    oldDoctor.phone       = updatedDoctor.phone;
                    oldDoctor.username    = updatedDoctor.username;
                    oldDoctor.destrictID  = updatedDoctor.destrictID;
                    db.doctors.Attach(oldDoctor);
                    db.Entry(oldDoctor).Collection(s => s.specialities).Load();
                    oldDoctor.specialities.Clear();
                    oldDoctor.specialities = new List <speciality>();
                    if (updatedDoctor.subSpID == null || updatedDoctor.subSpID.Count() == 0)
                    {//doctor has no sub specialities
                        oldDoctor.specialities.Add(db.specialities.Find(updatedDoctor.spID));
                    }
                    else
                    {
                        foreach (var spid in  updatedDoctor.subSpID)
                        {
                            byte spID = byte.Parse(spid);
                            oldDoctor.specialities.Add(db.specialities.Find(spID));
                        }
                    }
                    db.Entry(oldDoctor).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    MembershipUser docMember = Membership.GetUser();
                    docMember.Email = oldDoctor.mail;
                    if (oldusername != updatedDoctor.username)//if username has been changed
                    {
                        Guid         userID = (Guid)docMember.ProviderUserKey;
                        aspnet_Users user   = db.aspnet_Users.Where(us => us.UserId == userID).FirstOrDefault();
                        user.UserName        = updatedDoctor.username;
                        user.LoweredUserName = updatedDoctor.username.ToLower();
                    }//update user role
                    Membership.UpdateUser(docMember);
                    db.SaveChanges();
                    if (oldusername != updatedDoctor.username)
                    {//logout if username has been changed
                        return(logout());
                    }
                    return(View(updatedDoctor));
                }
                catch (Exception)
                {
                    ModelState.AddModelError(string.Empty, Resource1.updateOperationFaild);
                    return(View(updatedDoctor));
                }
            }
            else
            {
                return(View(updatedDoctor));
            }
        }
示例#3
0
 //submit register page information to create account
 public ActionResult register(doctorAccountData doctor)
 {
     if (ModelState.IsValid)
     {
         try
         {
             doctor newDoctor = new doctor();
             newDoctor.id = Guid.NewGuid();
             string imageName = "";
             //check if image is valid
             if (!validateProfessionImage(newDoctor.id.ToString(), ref imageName))
             {//image is not valid
                 ModelState.AddModelError("proImage", Resource1.professionImgNotValid);
                 fillViewDataForDoctorRegistrationForm(doctor.cityID, doctor.destrictID, doctor.spID, doctor.subSpID);
                 return(View());
             }
             newDoctor.dateOfJoin   = DateTime.Now;
             newDoctor.bookingType  = doctor.bookingType;
             newDoctor.mail         = doctor.mail;
             newDoctor.password     = doctor.password;
             newDoctor.phone        = doctor.phone;
             newDoctor.proImage     = imageName;
             newDoctor.username     = doctor.username;
             newDoctor.destrictID   = doctor.destrictID;
             newDoctor.specialities = new List <speciality>();
             //if the selected specialiy has sub specialities
             if (doctor.subSpID != null && db.specialities.Any(s => s.id == doctor.spID && s.subSpecialites.Count > 0))
             {//the doctor selected sub specialities from main speciality
                 foreach (string sp in doctor.subSpID.ToList())
                 {
                     byte spID = byte.Parse(sp);
                     newDoctor.specialities.Add(db.specialities.Find(spID));
                 }
             }
             else
             {//the doctor selected only main speciality
                 newDoctor.specialities.Add(db.specialities.Find(doctor.spID));
             }
             db.doctors.Add(newDoctor);//add new doctor account
             userVerification entry = new userVerification();
             entry.userID           = newDoctor.id;
             entry.verificationCode = Guid.NewGuid();
             db.userVerifications.Add(entry);//add verification record
             db.SaveChanges();
             //send email verification
             sendEmailVerification(entry.verificationCode.ToString(), newDoctor.mail, newDoctor.username);
             //add new doctor to role
             Membership.CreateUser(newDoctor.username, newDoctor.password, newDoctor.mail);
             Roles.AddUserToRole(newDoctor.username, "doctor");
             if (isDoctorAuthenticated)
             {
                 logout();
             }
             addAuthenticationCookie(newDoctor.username, true);
             return(RedirectToAction("profile"));
         }
         catch (Exception)
         {
             fillViewDataForDoctorRegistrationForm(doctor.cityID, doctor.destrictID, doctor.spID, new string[] { "" }.ToList());
             ModelState.AddModelError(string.Empty, Resource1.registerFaild);
             return(View());
         }
     }
     else
     {      //registeration data is not valid
         fillViewDataForDoctorRegistrationForm(doctor.cityID, doctor.destrictID, doctor.spID, doctor.subSpID);
         ModelState.AddModelError(string.Empty, Resource1.registerFaild);
         return(View());
     }
 }