コード例 #1
0
        public ActionResult Create([Bind(Include = "eventDescription,eventCategory,eventStartDate,eventEndDate,eventStartTime,eventEndTime,registration,adultPrice,childPrice,eventID,image")] eventsTable eventsTable, HttpPostedFileBase file)
        {
            //string fileName = Path.GetFileNameWithoutExtension(eventsTable.imageFile.FileName);
            //string extension = Path.GetExtension(eventsTable.imageFile.FileName);
            //fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
            //eventsTable.image = "~/Content/Images/" + fileName;
            //fileName = Path.Combine(Server.MapPath("~/Content/Images"), fileName);
            //eventsTable.imageFile.SaveAs(fileName);
            if (ModelState.IsValid)
            {
                string ImageName    = System.IO.Path.GetFileName(file.FileName);
                string physicalPath = Server.MapPath("~/Content/Images/" + ImageName);

                // save image in folder
                file.SaveAs(physicalPath);

                //save new record in database
                eventsTable.image = ImageName;
                db.eventsTables.Add(eventsTable);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(eventsTable));
        }
コード例 #2
0
        public IHttpActionResult PuteventsTable(int id, eventsTable eventsTable)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != eventsTable.eventID)
            {
                return(BadRequest());
            }

            db.Entry(eventsTable).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!eventsTableExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            eventsTable eventsTable = db.eventsTables.Find(id);

            db.eventsTables.Remove(eventsTable);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #4
0
 public ActionResult Edit([Bind(Include = "eventDescription,eventCategory,eventStartDate,eventEndDate,eventStartTime,eventEndTime,registration,adultPrice,childPrice,eventID,image")] eventsTable eventsTable)
 {
     if (ModelState.IsValid)
     {
         db.Entry(eventsTable).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(eventsTable));
 }
コード例 #5
0
        public IHttpActionResult PosteventsTable(eventsTable eventsTable)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            db.eventsTables.Add(eventsTable);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = eventsTable.eventID }, eventsTable));
        }
コード例 #6
0
        public IHttpActionResult GeteventsTable(int id)
        {
            eventsTable eventsTable = db.eventsTables.Find(id);

            if (eventsTable == null)
            {
                return(NotFound());
            }

            return(Ok(eventsTable));
        }
コード例 #7
0
        public IHttpActionResult DeleteeventsTable(int id)
        {
            eventsTable eventsTable = db.eventsTables.Find(id);

            if (eventsTable == null)
            {
                return(NotFound());
            }

            db.eventsTables.Remove(eventsTable);
            db.SaveChanges();

            return(Ok(eventsTable));
        }
コード例 #8
0
        // GET: eventsTables/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            eventsTable eventsTable = db.eventsTables.Find(id);

            if (eventsTable == null)
            {
                return(HttpNotFound());
            }
            return(View(eventsTable));
        }
コード例 #9
0
        public ActionResult Edit([Bind(Include = "eventDescription,eventCategory,eventStartDate,eventEndDate,eventStartTime,eventEndTime,registration,adultPrice,childPrice,eventID,image")] eventsTable eventsTable, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                string ImageName    = System.IO.Path.GetFileName(file.FileName);
                string physicalPath = Server.MapPath("~/Content/Images/" + ImageName);

                // save image in folder
                file.SaveAs(physicalPath);

                //save new record in database
                eventsTable.image           = ImageName;
                db.Entry(eventsTable).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(eventsTable));
        }