示例#1
0
 public ActionResult DeleteConfirmed(int id)
 {
     Moments.Models.Moments moments = db.Moments.Find(id);
     db.Moments.Remove(moments);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
示例#2
0
        public ActionResult Create(HttpPostedFileBase file, [Bind(Include = "Id,Username,Titel,Description,Image,Date,Place")] Moments.Models.Moments moments)
        {
            ViewBag.MetadataControll = db.Metadata.ToList();
            if (file != null && file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);
                var path     = Path.Combine(Server.MapPath("~/Images/"), fileName);
                moments.Image = "/Images/" + fileName;
                file.SaveAs(path);
            }
            else
            {
                return(Redirect("/Moments/Create")); //If there is no file you will be redirected to the same page
            }

            if (ModelState.IsValid)
            {
                db.Moments.Add(moments);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Username = new SelectList(db.Login, "Id", "Username", moments.Username);
            ViewBag.Place    = new SelectList(db.Place, "Id", "Country", moments.Place);
            return(Redirect("/Moments/"));
        }
示例#3
0
 public ActionResult Edit([Bind(Include = "Id,Username,Titel,Description,Image,Date,Place")] Moments.Models.Moments moments)
 {
     if (ModelState.IsValid)
     {
         db.Entry(moments).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Username = new SelectList(db.Login, "Id", "Username", moments.Username);
     ViewBag.Place    = new SelectList(db.Place, "Id", "Country", moments.Place);
     return(View(moments));
 }
示例#4
0
 // GET: Moments/Details/5
 public ActionResult Details(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     Moments.Models.Moments moments = db.Moments.Find(id);
     if (moments == null)
     {
         return(HttpNotFound());
     }
     return(View(moments));
 }
示例#5
0
 // GET: Moments/Edit/5
 public ActionResult Edit(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     Moments.Models.Moments moments = db.Moments.Find(id);
     if (moments == null)
     {
         return(HttpNotFound());
     }
     ViewBag.Username = new SelectList(db.Login, "Id", "Username", moments.Username);
     ViewBag.Place    = new SelectList(db.Place, "Id", "Country", moments.Place);
     return(View(moments));
 }
示例#6
0
        // GET: MomentPage
        // GET: Moments

        public ActionResult Index()
        {
            ViewBag.MetadataControll = db.Metadata.ToList();
            if (System.Web.HttpContext.Current.Session["UserName"] == null)
            {
                return(Redirect("~/Logins/Index"));
            }
            else
            {
                //Save the item the user chose to view more about to be able to show it in a separate page
                int key = int.Parse(Request.Params["item.Id"]);
                Moments.Models.Moments chosenMoment = db.Moments.Find(key);

                Moments.Models.Place country = dbPlace.Place.Find(chosenMoment.Place);
                ViewBag.Country = country.Country;
                return(View(chosenMoment));
            }
        }
示例#7
0
 // GET: Moments/Details/5
 public ActionResult Details(int?id)
 {
     ViewBag.MetadataControll = db.Metadata.ToList();
     if (System.Web.HttpContext.Current.Session["UserName"] == null)
     {
         return(Redirect("~/Logins/Index"));
     }
     else
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         Moments.Models.Moments moments = db.Moments.Find(id);
         if (moments == null)
         {
             return(HttpNotFound());
         }
         return(View(moments));
     }
 }
示例#8
0
 // GET: Moments/Edit/5
 public ActionResult Edit(int?id)
 {
     ViewBag.MetadataControll = db.Metadata.ToList();
     if (System.Web.HttpContext.Current.Session["UserName"] == null)
     {
         return(Redirect("~/Logins/Index"));
     }
     else
     {
         if (id == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
         }
         Moments.Models.Moments moments = db.Moments.Find(id);
         if (moments == null)
         {
             return(HttpNotFound());
         }
         ViewBag.Username = new SelectList(db.Login, "Id", "Username", moments.Username);
         ViewBag.Place    = new SelectList(db.Place, "Id", "Country", moments.Place);
         return(View(moments));
     }
 }