public new ActionResult Profile(Patient patient)
        {
            if (ModelState.IsValid)
            {
                var isExist = SecurityUtilities.IsEmailExists(patient.Email);
                if (isExist)
                {
                    if (db.Patients.Where(p => p.ID == patient.ID).Select(p => p.Email).FirstOrDefault() != patient.Email)
                    {
                        //username is registered before
                        ModelState.AddModelError("EmailExist", "Email already exists .");
                        ViewBag.BloodGroupID = new SelectList(db.BloodGroups, "ID", "Name", patient.BloodGroupID);
                        return(View(patient));
                    }
                }

                // saving data
                patient.PW = SecurityUtilities.Hash(patient.PW);
                db.Entry(patient).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            //if we reach here something went wrong
            ModelState.AddModelError("ProfileError", "An error occured while editing profile");
            ViewBag.BloodGroupID = new SelectList(db.BloodGroups, "ID", "Name", patient.BloodGroupID);
            return(View(patient));
        }
        public ActionResult Register(Patient patient, HttpPostedFileBase uploaded)
        {
            if (ModelState.IsValid)
            {
                var isExist = SecurityUtilities.IsEmailExists(patient.Email);
                if (isExist)
                {
                    //username is registered before
                    ModelState.AddModelError("EmailExist", "Email already exists .");
                    ViewBag.BloodGroupID = new SelectList(db.BloodGroups, "ID", "Name", patient.BloodGroupID);
                    return(View(patient));
                }
                //Completing user model data
                patient.PW = SecurityUtilities.Hash(patient.PW);
                if (uploaded != null && uploaded.ContentLength > 0)
                {
                    string extension = Path.GetExtension(uploaded.FileName);
                    string pattern   = @".(jpg|JPG|jpeg|JPEG|png|PNG)$";
                    if (Regex.IsMatch(extension, pattern))
                    {
                        // convert image to array of binary
                        patient.Img = new byte[uploaded.ContentLength];
                        uploaded.InputStream.Read(patient.Img, 0, uploaded.ContentLength);
                    }
                    else
                    {
                        ModelState.AddModelError("ImgError", "Only Images allowed .");
                        ViewBag.BloodGroupID = new SelectList(db.BloodGroups, "ID", "Name", patient.BloodGroupID);
                        return(View(patient));
                    }
                }
                // insert user data in User and UserRoles tables in one transaction

                db.Patients.Add(patient);
                db.SaveChanges();

                //Registeration succeeded, Sign in this account
                Response.Cookies.Add(SecurityUtilities.CreateAuthenticationCookie(patient.FName, patient.ID.ToString()));

                // Redirect to Dashboard
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("RegisterError", "An error occured while registeration .");
            }
            // If we got this far, something failed, redisplay form
            ViewBag.BloodGroupID = new SelectList(db.BloodGroups, "ID", "Name", patient.BloodGroupID);
            return(View(patient));
        }