public ActionResult Delete(T_Upload m) { if (Del(m.ID)) { return(RedirectToAction("Index")); } return(JsonOut(new { status = false })); }
public ActionResult Upload() { var fileName = Request.Form["name"]; var part = int.Parse(Request.Form["part"]); var parts = int.Parse(Request.Form["parts"]); var size = int.Parse(Request.Form["size"]); var FileDataContent = Request.Files[0]; if (FileDataContent != null && FileDataContent.ContentLength > 0) { var stream = FileDataContent.InputStream; var UploadPath = Server.MapPath("~/uploads"); Directory.CreateDirectory(UploadPath); var path = Path.Combine(UploadPath, fileName); try { using (var fileStream = new FileStream(path, FileMode.Append, FileAccess.Write)) { stream.CopyTo(fileStream); } //last part? if (part + 1 >= parts) { var newid = Guid.NewGuid(); var newName = newid.ToString() + "_" + fileName; var newPath = Path.Combine(UploadPath, newName); System.IO.File.Move(path, newPath); //rename var n = new T_Upload { ID = newid, Name = fileName, //display name Path = newName, //physical name Size = size, UploadDate = DateTime.Now }; db.T_Upload.Add(n); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (IOException ex) { // handle Response.StatusCode = 500; return(Json(new { status = "fail", error = ex.Message })); } } return(Json(new { status = "success" })); }
public ActionResult Update(T_Upload m) { if (ModelState.IsValid) { db.Entry(m).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(JsonOut(ModelState)); }