public ActionResult Upload(Guid id, string tags) { var record = BasicWebManager.Get <File>(id); Guid fileID = id; var file = Request.Files["file"]; if (string.IsNullOrEmpty(file.FileName)) { ModelState.AddModelError("file", "请选择文件"); } if (ModelState.IsValid) { if (record == null) { record = new File { ID = fileID, Name = file.FileName, PostTime = DateTime.Now, PostUser = WebMatrix.WebData.WebSecurity.CurrentUserName, Tags = tags, Size = file.ContentLength }; BasicWebManager.New(record); } else // 不允许修改PostUser { BasicWebManager.Update <File>(id, x => { x.Name = file.FileName; x.PostTime = DateTime.Now; x.Tags = tags; x.Size = file.ContentLength; }); } file.SaveAs(GetUploadFileName(fileID)); } return(RedirectToAction("Detail", new { id })); }
public ActionResult UploadToGroup(string id, string tags) { string type; string group; if (id == null) { id = string.Empty; } if (id.Contains('|')) { var parts = id.Split('|'); type = parts[0]; group = parts[1]; } else { type = string.Empty; group = id; } Guid fileID = Guid.NewGuid(); var file = Request.Files["file"]; if (string.IsNullOrEmpty(file.FileName)) { ModelState.AddModelError("file", "请选择文件"); } if (ModelState.IsValid) { File record = new File { ID = fileID, Name = file.FileName, Group = group, Type = type, PostTime = DateTime.Now, PostUser = WebMatrix.WebData.WebSecurity.CurrentUserName, Tags = tags, Size = file.ContentLength }; BasicWebManager.New(record); file.SaveAs(GetUploadFileName(fileID)); } return(RedirectToAction("List", new { id })); }