public ActionResult DeleteConfirmed(int id)
        {
            PresidentWord presidentWord = db.PresidentWords.Find(id);

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

            if (presidentWord == null)
            {
                return(HttpNotFound());
            }
            return(View(presidentWord));
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "PresidentWordId,Name,Description,Text,Path,Code")] PresidentWord presidentWord, 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('PresidentWords') + IDENT_INCR('PresidentWords')";
                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)
                {
                    throw;
                }

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

                //string path = Path.Combine(Server.MapPath("~/ImagesOfProject/CenterManagerPhotos"), Image.FileName);
                //Image.SaveAs(path);
                //presidentWord.Path = "~/ImagesOfProject/CenterManagerPhotos/" + Image.FileName;

                presidentWord.Code = 3;
                db.PresidentWords.Add(presidentWord);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

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

                presidentWord.Code            = 1;
                db.Entry(presidentWord).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(presidentWord));
        }