public ActionResult Create(NavigationTrack navigationtrack)
        {
            if (ModelState.IsValid)
            {
                db.NavigationTrack.Add(navigationtrack);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.RouteId = new SelectList(db.NavigationRoute, "Id", "Name", navigationtrack.RouteId);
            return View(navigationtrack);
        }
        public ActionResult FileUpload(HttpPostedFileBase file, string routeselect)
        {
            FileUpload f = new FileUpload();

            int fileLength = file.ContentLength;
            byte[] myData = new Byte[fileLength];
            file.InputStream.Read(myData, 0, fileLength);

            DateTime r = DateTime.Now;
            string fileName = r.Year.ToString() + r.Month.ToString() + r.Day.ToString() + r.Hour.ToString() + r.Minute.ToString() + r.Second.ToString() + "img-" + file.FileName;
            string url = "\\images\\" + fileName;

            System.IO.FileStream newFile
                = new System.IO.FileStream(Server.MapPath(url),
                                           System.IO.FileMode.Create);
            newFile.Write(myData, 0, myData.Length);
            newFile.Close();

            f.SaveAs(url);

            if (file != null)
            {
                byte[] bytes = new byte[file.ContentLength];
                file.InputStream.Read(bytes, 0, Convert.ToInt32(file.ContentLength));
                NavigationTrack navigationtrack = new NavigationTrack();
                int routeId = Convert.ToInt32(routeselect);
                navigationtrack.Route = db.NavigationRoute.Where(x => x.Id == routeId).ToList().First();
                /*string baseString = Convert.ToBase64String(bytes);*/
                navigationtrack.Image = url;
                navigationtrack.FileName = fileName;

                db.NavigationTrack.Add(navigationtrack);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            // after successfully uploading redirect the user
            return RedirectToAction("Index", "NavigationTrack");
        }
 public ActionResult Edit(NavigationTrack navigationtrack)
 {
     if (ModelState.IsValid)
     {
         db.Entry(navigationtrack).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.RouteId = new SelectList(db.NavigationRoute, "Id", "Name", navigationtrack.RouteId);
     return View(navigationtrack);
 }