Ejemplo n.º 1
0
 public ActionResult LinkShow(int id)
 {
     ResourceLink link = new ResourceLink();
     link = db.ResourceLinks.Find(id);
     ViewBag.ResourceLink = new vResourceLink(link);
     return View();
 }
Ejemplo n.º 2
0
 public ActionResult LinkEdit(ResourceLink model, HttpPostedFileBase file)
 {
     int fileId = 0;
     if (file != null && model.IsHaveFile)
     {
         if (model.FileID != 0)
         {
             string fileName = Path.Combine(Request.MapPath("~/Upload"), DateHelper.GetTimeStamp() + Path.GetFileName(file.FileName));
             file.SaveAs(fileName);
             Models.File _file = new Models.File();
             _file = db.Files.Find(model.FileID);
             _file.FileTypeID = model.LinkTypeID;
             _file.Path = DateHelper.GetTimeStamp() + Path.GetFileName(file.FileName);
             _file.ContentType = file.ContentType;
             _file.FileName = file.FileName;
             _file.FileSize = file.ContentLength.ToString();
             db.SaveChanges();
             fileId = _file.ID;
         }
         else
         {
             string fileName = Path.Combine(Request.MapPath("~/Upload"), DateHelper.GetTimeStamp() + Path.GetFileName(file.FileName));
             file.SaveAs(fileName);
             Models.File _file = new Models.File();
             _file.FileTypeID = model.LinkTypeID;
             _file.Path = DateHelper.GetTimeStamp() + Path.GetFileName(file.FileName);
             _file.Time = DateTime.Now;
             _file.ContentType = file.ContentType;
             _file.FileName = file.FileName;
             _file.FileSize = file.ContentLength.ToString();
             db.Files.Add(_file);
             db.SaveChanges();
             fileId = _file.ID;
         }
     }
     if (!model.IsHaveFile)
     {
         if (model.FileID != 0)
         {
             Models.File _file = new Models.File();
             _file = db.Files.Find(model.FileID);
             var path = Server.MapPath("~/Upload/" + _file.Path);
             System.IO.File.Delete(path);
             db.Files.Remove(_file);
             db.SaveChanges();
             fileId = 0;
         }
     }
     ResourceLink link = new ResourceLink();
     link = db.ResourceLinks.Find(model.ID);
     link.IsHaveFile = model.IsHaveFile;
     link.LinkTypeID = model.LinkTypeID;
     link.Title = model.Title;
     link.URL = model.URL;
     link.FileID = fileId;
     db.SaveChanges();
     return RedirectToAction("LinkManager");
 }
Ejemplo n.º 3
0
 public ActionResult LinkDelete(int id)
 {
     ResourceLink link = new ResourceLink();
     link = db.ResourceLinks.Find(id);
     db.ResourceLinks.Remove(link);
     if (link.IsHaveFile)
     {
         Models.File file = new Models.File();
         file = db.Files.Find(link.FileID);
         var path = Server.MapPath("~/Upload/" + file.Path);
         System.IO.File.Delete(path);
         db.Files.Remove(file);
     }
     db.SaveChanges();
     return Content("ok");
 }
Ejemplo n.º 4
0
 public ActionResult LinkEdit(int id)
 {
     List<TypeDictionary> CourseTypes = new List<TypeDictionary>();
     CourseTypes = db.TypeDictionaries.Where(td => td.FatherID == 0 && td.Belonger == TypeBelonger.资源链接).ToList();
     ViewBag.Types = CourseTypes;
     ResourceLink link = new ResourceLink();
     link = db.ResourceLinks.Find(id);
     ViewBag.ResourceLink = new vResourceLink(link);
     return View();
 }
Ejemplo n.º 5
0
 public ActionResult AddLink(ResourceLink model, HttpPostedFileBase file)
 {
     int fileId = 0;
     if (model.IsHaveFile)
     {
         string fileName = Path.Combine(Request.MapPath("~/Upload"), DateHelper.GetTimeStamp() + Path.GetFileName(file.FileName));
         file.SaveAs(fileName);
         Models.File _file = new Models.File();
         _file.FileTypeID = model.LinkTypeID;
         _file.Path = DateHelper.GetTimeStamp() + Path.GetFileName(file.FileName);
         _file.Time = DateTime.Now;
         _file.ContentType = file.ContentType;
         _file.FileName = file.FileName;
         _file.FileSize = file.ContentLength.ToString();
         db.Files.Add(_file);
         db.SaveChanges();
         fileId = _file.ID;
     }
     ResourceLink link = new ResourceLink();
     link.IsHaveFile = model.IsHaveFile;
     link.LinkTypeID = model.LinkTypeID;
     link.Time = DateTime.Now;
     link.Title = model.Title;
     link.URL = model.URL;
     link.UserID = CurrentUser.ID;
     link.FileID = fileId;
     db.ResourceLinks.Add(link);
     db.SaveChanges();
     return RedirectToAction("LinkManager");
 }