Exemple #1
0
        public ActionResult Create([Bind(Include = "Id,FootballCourtName,Description,Latitude,Longitude,Email,Address,FK_Category,Phone,Image,FK_AreaId,Website")] FootballCourt footballCourt, HttpPostedFileBase img)
        {
            if (ModelState.IsValid)
            {
                string file_name = "";
                if (img != null && img.ContentLength > 0)
                {
                    try
                    {
                        file_name = Guid.NewGuid() + Path.GetFileName(img.FileName);
                        string path = Path.Combine(Server.MapPath("~/images"),
                                                   file_name);
                        img.SaveAs(path);
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Message = "ERROR:" + ex.Message.ToString();
                    }
                }
                footballCourt.Image = file_name;

                db.FootballCourts.Add(footballCourt);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.FK_AreaId   = new SelectList(db.Areas, "Id", "AreaName", footballCourt.FK_AreaId);
            ViewBag.FK_Category = new SelectList(db.Categories, "Id", "CategoryName", footballCourt.FK_Category);
            return(View(footballCourt));
        }
Exemple #2
0
        public ActionResult DeleteConfirmed(long id)
        {
            FootballCourt footballCourt = db.FootballCourts.Find(id);

            db.FootballCourts.Remove(footballCourt);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #3
0
        // GET: FootballCourts/Details/5
        public ActionResult Details(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FootballCourt footballCourt = db.FootballCourts.Find(id);

            if (footballCourt == null)
            {
                return(HttpNotFound());
            }
            return(View(footballCourt));
        }
Exemple #4
0
        // GET: FootballCourts/Edit/5
        public ActionResult Edit(long?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FootballCourt footballCourt = db.FootballCourts.Find(id);

            if (footballCourt == null)
            {
                return(HttpNotFound());
            }
            ViewBag.FK_AreaId   = new SelectList(db.Areas, "Id", "AreaName", footballCourt.FK_AreaId);
            ViewBag.FK_Category = new SelectList(db.Categories, "Id", "CategoryName", footballCourt.FK_Category);
            return(View(footballCourt));
        }