コード例 #1
0
 public ActionResult DeleteConfirmed(int id)
 {
     inz.Models.File file = db.Files.Find(id);
     db.Files.Remove(file);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "Id,Name,Date,Path")] inz.Models.File file)
 {
     if (ModelState.IsValid)
     {
         db.Entry(file).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(file));
 }
コード例 #3
0
 // GET: Files/Delete/5
 public ActionResult Delete(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     inz.Models.File file = db.Files.Find(id);
     if (file == null)
     {
         return(HttpNotFound());
     }
     return(View(file));
 }
コード例 #4
0
        public ActionResult Create([Bind(Include = "Id,Name,Date,Path,ProjectID ")] inz.Models.File file, HttpPostedFileBase UserFile, string projID)
        {
            if (ModelState.IsValid)
            {
                if (UserFile != null && UserFile.ContentLength > 0)
                {
                    //file.ProjectID = Int32.Parse(Request.Params["ProjectID"]);
                    file.ProjectID = Int32.Parse(projID);
                    // extract only the filename
                    var fileName = Path.GetFileName(UserFile.FileName);

                    var temp = db.Files
                               .Where(x => x.Path == fileName)
                               .Select(x => x.Path)
                               .FirstOrDefault();

                    int count = 0;
                    while (temp != null)
                    {
                        Random rand = new Random();
                        int    num  = rand.Next(1, 99);
                        fileName = num.ToString() + "-" + fileName;

                        temp = db.Files
                               .Where(x => x.Path == fileName)
                               .Select(x => x.Path)
                               .FirstOrDefault();
                        count++;
                        if (count >= 100)
                        {
                            return(RedirectToAction("Index"));
                        }
                    }

                    // store the file inside ~/App_Data/uploads folder
                    var path = Path.Combine(Server.MapPath("~/App_Data/uploads"), fileName);
                    UserFile.SaveAs(path);

                    file.Date = DateTime.Now;
                    file.Path = fileName;

                    db.Files.Add(file);
                    db.SaveChanges();
                }
                // redirect back to the index action to show the form once again
                return(RedirectToAction("../Projects/Details/" + file.ProjectID));
            }

            return(RedirectToAction("../Projects/Details/" + file.ProjectID));
        }
コード例 #5
0
        // GET: Files/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            inz.Models.File file = db.Files.Find(id);
            if (file == null)
            {
                return(HttpNotFound());
            }
            string virtualFilePath = "~/App_Data/uploads/" + file.Path.ToString();

            return(File(virtualFilePath, System.Net.Mime.MediaTypeNames.Application.Octet, Path.GetFileName(virtualFilePath)));
            //return View(file);
        }