//Inserting doctor into database
 public bool commitInsert(doctor doc)
 {
     using (objLinq)
     {
         objLinq.doctors.InsertOnSubmit(doc);
         objLinq.SubmitChanges();
         return true;
     }
 }
        public ActionResult CreateDoctor(CreateDoctorModel model, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {

                    doctor objDoctor = new doctor();
                   // Upload the image of doctor on server
                    if (image != null)
                    {
                        string doctor_photo = Path.GetFileName(image.FileName);
                        string image_ext = Path.GetExtension(image.FileName);

                        doctor_photo = DateTime.UtcNow.Ticks + doctor_photo;
                        objDoctor.photo_path = doctor_photo;

                        string path = Path.Combine(Server.MapPath("~/Content/images/doctors/"), doctor_photo);
                        image.SaveAs(path);
                    }

                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);

                    //Add a role to the new user
                    Roles.AddUserToRole(model.UserName, "Doctor");

                    //Create doctor object based on user input

                    objDoctor.user_name = model.UserName;
                    objDoctor.department_name = model.department_name;
                    objDoctor.first_name = model.first_name;
                    objDoctor.last_name = model.last_name;
                    objDoctor.email = model.email;
                    objDoctor.phone = model.phone;
                    objDoctor.specialty = model.specialty;
                    objDoctor.bio = model.bio;

                    //Insert doctor object to database doctor table

                    objDoc.commitInsert(objDoctor);

                    return RedirectToAction("ListDoctor", "UserAdmin");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }
            return View(model);
        }
 partial void Deletedoctor(doctor instance);
 partial void Updatedoctor(doctor instance);
 partial void Insertdoctor(doctor instance);
        public ActionResult DoctorDelete(int id, doctor doc)
        {
            var UserName = doc.user_name;
            try
            {

                // Deleting the photo of this doctor
                var image = doc.photo_path;
                string fullPath = Server.MapPath("~/Content/images/doctors/"
                + image);

                if (System.IO.File.Exists(fullPath))
                {
                    System.IO.File.Delete(Server.MapPath("~/Content/images/doctors/"
                + image));

                }

                // Deleting Doctor from doctor table and remove all profile and acount ...
                objDoc.commitDelete(id);
                Roles.RemoveUserFromRole(UserName, "doctor");
                Membership.DeleteUser(UserName);
                return RedirectToAction("ListDoctor");
            }
            catch
            {
                return View();
            }
        }