示例#1
0
        public ActionResult Edit(Table_Promote table_Promote, HttpPostedFileBase file)
        {
            try
            {
                var recordToUpdate = db.Table_Promote.AsNoTracking().Single(x => x.Promote_ID == table_Promote.Promote_ID);
                if (file != null && file.ContentLength > 0)
                {
                    var    myUniqueFileName = DateTime.Now.Ticks + ".jpg";
                    string physicalPath     = Server.MapPath("~/img/" + myUniqueFileName);
                    file.SaveAs(physicalPath);
                    table_Promote.Promote_Pic = myUniqueFileName;
                }
                else
                {
                    table_Promote.Promote_Pic = recordToUpdate.Promote_Pic;
                }
            }
            catch (Exception)
            {
                ViewBag.Message = "อัพเดทข้อมูลไม่สำเร็จ กรุณาตรวจสอบข้อมูลและลองใหม่อีกครั้ง";
            }


            db.Entry(table_Promote).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#2
0
        public ActionResult showdetails(int id)
        {
            var vm = new Table_Promote();

            var question = db.Table_Promote.FirstOrDefault(a => a.Promote_ID == id);

            if (question != null)
            {
                vm = question;
            }

            return(PartialView(vm));
        }
示例#3
0
 public ActionResult Create(Table_Promote table_Promote, HttpPostedFileBase file)
 {
     if (file != null && file.ContentLength > 0)
     {
         var    myUniqueFileName = DateTime.Now.Ticks + ".jpg";
         string physicalPath     = Server.MapPath("~/img/" + myUniqueFileName);
         file.SaveAs(physicalPath);
         table_Promote.Promote_Pic = myUniqueFileName;
     }
     db.Table_Promote.Add(table_Promote);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
示例#4
0
        // GET: Table_Promote/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Table_Promote table_Promote = db.Table_Promote.Find(id);

            if (table_Promote == null)
            {
                return(HttpNotFound());
            }
            return(View(table_Promote));
        }
示例#5
0
        // GET: Table_Promote/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Table_Promote table_Promote = db.Table_Promote.Find(id);

            if (table_Promote == null)
            {
                return(HttpNotFound());
            }
            db.Table_Promote.Remove(table_Promote);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }