public ActionResult DeleteConfirmed(int id)
        {
            CenterPhoto centerPhoto = db.CenterPhotos.Find(id);

            db.CenterPhotos.Remove(centerPhoto);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: CenterPhotoes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CenterPhoto centerPhoto = db.CenterPhotos.Find(id);

            if (centerPhoto == null)
            {
                return(HttpNotFound());
            }
            return(View(centerPhoto));
        }
        public ActionResult Create([Bind(Include = "CenterPhotosId,Description,Path")] CenterPhoto centerPhoto, HttpPostedFileBase Image)
        {
            if (ModelState.IsValid)
            {
                //get  the id of the last row + 1
                string        ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
                SqlConnection con   = new SqlConnection(ConnectionString);
                string        Query = "SELECT IDENT_CURRENT('CenterPhotoes') + IDENT_INCR('CenterPhotoes')";
                SqlCommand    cmd   = new SqlCommand(Query, con);
                int           id    = 0;
                try
                {
                    con.Open();
                    SqlDataReader dr;
                    dr = cmd.ExecuteReader();
                    while (dr.Read())
                    {
                        id = Convert.ToInt32(dr[0]);
                    }
                    dr.Close();
                    con.Close();
                }
                catch (Exception e)
                {
                    Response.Write(e);
                }

                string path1_1    = Path.Combine(Server.MapPath("~/ImagesOfProject/CenterPhotos"), Image.FileName);
                string Extension1 = Path.GetExtension(path1_1);
                string path1_2    = Path.Combine(Server.MapPath("~/ImagesOfProject/CenterPhotos"), id + Extension1);
                Image.SaveAs(path1_2);
                string Domain = ConfigurationManager.AppSettings["Domain"].ToString();
                centerPhoto.Path = Domain + "/ImagesOfProject/CenterPhotos/" + id + Extension1;

                db.CenterPhotos.Add(centerPhoto);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(centerPhoto));
        }
        public ActionResult Edit([Bind(Include = "CenterPhotosId,Description,Path")] CenterPhoto centerPhoto, HttpPostedFileBase Image)
        {
            if (ModelState.IsValid)
            {
                int id = centerPhoto.CenterPhotosId;
                if (Image != null)
                {
                    string path1_1    = Path.Combine(Server.MapPath("~/ImagesOfProject/CenterPhotos"), Image.FileName);
                    string Extension1 = Path.GetExtension(path1_1);
                    string path1_2    = Path.Combine(Server.MapPath("~/ImagesOfProject/CenterPhotos"), id + Extension1);
                    Image.SaveAs(path1_2);
                    string Domain = ConfigurationManager.AppSettings["Domain"].ToString();
                    centerPhoto.Path = Domain + "/ImagesOfProject/CenterPhotos/" + id + Extension1;
                }

                //string path = Path.Combine(Server.MapPath("~/ImagesOfProject/CenterPhotos"), Image.FileName);
                //Image.SaveAs(path);
                //centerPhoto.Path = "~/ImagesOfProject/CenterPhotos/" + Image.FileName;
                db.Entry(centerPhoto).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(centerPhoto));
        }