コード例 #1
0
 public ActionResult DeleteConfirmed(int id)
 {
     using (CenterDBEntities db = new CenterDBEntities())
     {
         Instractors instractors = db.Instractors.Find(id);
         db.Instractors.Remove(instractors);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
コード例 #2
0
        // GET: Instractor/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            using (CenterDBEntities db = new CenterDBEntities())
            {
                Instractors instractors = db.Instractors.Include("InstractorStatus").Include("Gender").SingleOrDefault(x => x.ID == id.Value);

                if (instractors == null)
                {
                    return(HttpNotFound());
                }
                return(View(instractors));
            }
        }
コード例 #3
0
        public ActionResult Edit([Bind(Include = "ID,Instractor_EngName,Instractor_AraName,instractor_imagePath,,ImageUpload,Instractor_Address,Instractor_Mobile," + "Instractor_phone,Instractor_Email,Instractor_Facebook,instractor_twitter,Instractor_LinkedIn,Instractor_StatusID,Instractor_GenderID,Instractor_Birthdate,instractor_QualificationsEnglish")] Instractors instractors)
        {
            if (ModelState.IsValid)
            {
                string oldimagepath = "";
                using (CenterDBEntities db = new CenterDBEntities())
                {
                    oldimagepath = db.Instractors.Where(x => x.ID == instractors.ID).SingleOrDefault().instractor_imagePath;
                }
                using (CenterDBEntities db = new CenterDBEntities())
                {
                    if (instractors.ImageUpload != null && !string.IsNullOrEmpty(instractors.ImageUpload.FileName))
                    {
                        string subPath           = "~/Uploads/Photo/instractors/";
                        var    filename          = Path.GetFileName(instractors.ImageUpload.FileName);
                        var    formattedFileName = string.Format("{0}-{1}{2}"
                                                                 , instractors.Instractor_EngName
                                                                 , instractors.ID
                                                                 , Path.GetExtension(filename));
                        bool exists = System.IO.Directory.Exists(subPath);

                        if (!exists)
                        {
                            System.IO.Directory.CreateDirectory(Server.MapPath("~/Uploads/Photo/instractors/"));
                        }
                        subPath = Path.Combine("~/Uploads/Photo/instractors/", formattedFileName);
                        var path = Server.MapPath(subPath);
                        instractors.ImageUpload.SaveAs(path);
                        instractors.instractor_imagePath = subPath;
                    }
                    else
                    {
                        instractors.instractor_imagePath = oldimagepath;
                    }
                    db.Entry(instractors).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.Instractor_GenderID = UImanger.GenderDll();
            ViewBag.Instractor_StatusID = InstractorsRoutines.GetInstractorStatusDLL();
            return(View(instractors));
        }
コード例 #4
0
        // GET: Instractor/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            using (CenterDBEntities db = new CenterDBEntities())
            {
                Instractors instractors = db.Instractors.Find(id);

                if (instractors == null)
                {
                    return(HttpNotFound());
                }
                ViewBag.Instractor_GenderID = UImanger.GenderDll();
                ViewBag.Instractor_StatusID = InstractorsRoutines.GetInstractorStatusDLL();
                return(View(instractors));
            }
        }