public ActionResult Create(DocumentCreateViewModel model, int[] selectedRules) { Document document = new Document(); if (ModelState.IsValid) { model.SetValues(document); Helper.updateObjectFields(document); document.createUser = WebSecurity.CurrentUserId; document.companyID = (int)db.Users.Find(document.createUser).companyID; document.statusID = 1; if (selectedRules != null) { foreach (int rl in selectedRules) { document.Rules.Add(db.Rules.Find(rl)); } } document.EDT = 1; db.Documents.Add(document); db.SaveChanges(); return(RedirectToAction("Index")); } int?companyID = db.Users.Find(WebSecurity.CurrentUserId).companyID; ViewBag.documentTypeID = new SelectList(db.DocumentTypes, "ID", "name", document.documentTypeID); ViewBag.documentParentID = new SelectList(db.Documents.Where(dep => dep.companyID == companyID), "ID", "title", document.documentParentID); ViewBag.createUser = new SelectList(db.Users, "ID", "name", document.createUser); ViewBag.allRules = Helper.GetRulesSelect(db); return(View(document)); }
public ViewResult Create(DocumentCreateViewModel model) { if (ModelState.IsValid) { string fileFullName = model.Name + ".docx"; string relativePath = DirectoryPathHelper.GetRelativePath(fileFullName, Server.MapPath); string absolutePath = Server.MapPath(relativePath); CreateDocumentHelper.Create(absolutePath, model.Content); DocxToPdfHelper.Convert(absolutePath); Author author = repository.Authors.Single(a => a.Login == UserName); Document doc = new Document() { Author = author, Date = DateTime.Now, Name = model.Name, Url = relativePath }; repository.AddDocument(doc); return(View("Message", doc)); } else { return(View()); } }
public static void UpdateDocument(this Document document, DocumentCreateViewModel documentCreateViewModel) { document.Name = documentCreateViewModel.Name; document.Summary = documentCreateViewModel.Summary; document.Tag = documentCreateViewModel.Tag; document.Content = documentCreateViewModel.Content; }
public ViewResult Create(string id) { DocumentCreateViewModel documentCreateViewModel = new DocumentCreateViewModel() { ProjectID = id }; return(View(documentCreateViewModel)); }
/// <summary> /// /// </summary> /// <param name="viewModel"></param> /// <returns></returns> public async Task CreateByViewModelAsync(DocumentCreateViewModel viewModel) { if (viewModel == null) { throw new ArgumentNullException(nameof(viewModel)); } var document = _mapper.Map <Document>(viewModel); _documentRepository.Add(document); await _unitOfWork.SaveAllChangesAsync(auditUserId : _httpContextManager.CurrentUserId()); }
// // GET: /Document/Create public ActionResult Create() { var documents = new Documents(); var viewModel = new DocumentCreateViewModel { Events = HlpView.EventsForDocs, Status = HlpView.Status, Type = HlpView.DocType, Group = HlpView.Group, Doc = documents }; return(View(viewModel)); }
public ActionResult Create(DocumentCreateViewModel model, HttpPostedFileBase file) { if (ModelState.IsValid && file != null) { var newDocumentId = this.documents .Add(model.Title, model.Description, model.Code, model.ProcedureId); this.SaveDocumentFile(newDocumentId, file); TempData["Success"] = SuccessMessagesConstants.DocumentCreated; return(RedirectToAction("Details", new { id = newDocumentId })); } ViewBag.Procedures = GetProceduresListItems(); return(View(model)); }
public virtual async Task <ActionResult> Create(DocumentCreateViewModel viewModel) { if (viewModel == null) { return(View(MVC.Error.Views.BadRequest)); } if (ModelState.IsValid == false) { return(View(MVC.Document.Views.Create, viewModel)); } await _documentService.CreateByViewModelAsync(viewModel); this.AddToastMessage("افزودن پرونده با موفقیت انجام شد", "", ToastType.Success); return(RedirectToAction(MVC.Document.List())); }
public async Task <IActionResult> Create(DocumentCreateViewModel model) { if (ModelState.IsValid) { string uniqueFileName = null; if (model.Files != null && model.Files.Count > 0) { foreach (var file in model.Files) { //必须将图像上传到wwwroot中的images文件夹 //而要获取wwwroot文件夹的路径,我们需要注入 ASP.NET Core提供的HostingEnvironment服务 //通过HostingEnvironment服务去获取wwwroot文件夹的路径 string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "files"); //为了确保文件名是唯一的,我们在文件名后附加一个新的GUID值和一个下划线 uniqueFileName = Guid.NewGuid().ToString() + "_" + file.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); //因为使用了非托管资源,所以需要手动进行释放 using (var fileStream = new FileStream(filePath, FileMode.Create)) { //使用IFormFile接口提供的CopyTo()方法将文件复制到wwwroot/images文件夹 file.CopyTo(fileStream); } var aa = await _userManager.GetUserAsync(HttpContext.User); Document newDocument = new Document { ProjectID = model.ProjectID, UploadDate = DateTime.Now, FileSize = ((double)file.Length / 1048576).ToString("F1") + "MB", Uploader = aa.UserName, FilePath = uniqueFileName, FileName = file.FileName }; _documentRepository.Add(newDocument); } } return(RedirectToAction("Details", new { id = model.ProjectID })); } return(View()); }
public ActionResult Create(DocumentCreateViewModel documentCreateViewModel) { Document document = new Document(); document.UpdateDocument(documentCreateViewModel); document.New(User.Identity.Name); if (ModelState.IsValid) { List<DocumentFile> fileDetails = new List<DocumentFile>(); for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); DocumentFile fileDetail = new DocumentFile { Id = Guid.NewGuid(), Name = fileName, Type = file.ContentType }; long? size = file.ContentLength; fileDetail.Size = size.ToString(); fileDetail.Path = Path.GetExtension(fileName); fileDetails.Add(fileDetail); var path = Path.Combine(Server.MapPath(_uploadPath), fileDetail.Id + fileDetail.Path); file.SaveAs(path); } } document.DocumentFiles = fileDetails; db.Documents.Add(document); db.SaveChanges(); return RedirectToAction("Index"); } return View(document); }
public async Task <IActionResult> OnPostAsync(DocumentCreateViewModel model) { if (!ModelState.IsValid) { string fileUniqueName = null; if (model.Document == null) { string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "Documents"); fileUniqueName = Guid.NewGuid().ToString(); string filePath = Path.Combine(uploadsFolder, fileUniqueName); if (filePath.Length > 0) { using (var fs = new FileStream(filePath, FileMode.Create)) { fs.Position = 0; await fs.CopyToAsync(fs); fs.Close(); } } DocumentModel newDocument = new DocumentModel { Name = documentModel.Name, Description = documentModel.Description, DocumentPath = fileUniqueName }; _db.Add(newDocument); await _db.SaveChangesAsync(); } } return(Page()); }
public ActionResult Create(DocumentCreateViewModel documents, HttpPostedFileBase DocFile) { string sPath = string.Empty; int docPK = 0; if (DocFile == null) //nothing to do.. { return(RedirectToAction("ListAll")); } try { //filter document type switch (Path.GetExtension(DocFile.FileName.ToLower())) { case ".pdf": case ".doc": case ".txt": case ".ppt": case ".xls": break; default: TempData["WrongType"] = "Fehler: Nur PDF, DOC, XLS, PPT & TXT - Files sind zugelassen"; return(RedirectToAction("ListAll")); } string fileName = Path.GetFileName(DocFile.FileName.Split('.').First() + "_" + DateTime.Now.ToShortDateString() + '.' + Path.GetFileName(DocFile.FileName.Split('.').Last())); if (ModelState.IsValid) { documents.Doc.Status = documents.SelectedStatusValue; documents.Doc.EventId = documents.SelectedEventValue; documents.Doc.Type = documents.SelectedTypeValue; documents.Doc.GroupId = documents.SelectedGroupValue; documents.Doc.UserId = WebSecurity.GetUserId(User.Identity.Name); documents.Doc.CreateDate = DateTime.Now; documents.Doc.FilePath = Path.Combine(Server.MapPath("~/Documents"), fileName); documents.Doc.FileExtension = Path.GetExtension(DocFile.FileName); db.Documents.AddObject(documents.Doc); db.SaveChanges(); docPK = documents.Doc.DocId; //update filepath Documents doc = db.Documents.Single(d => d.DocId == docPK); doc.FilePath = Path.Combine(Server.MapPath("~/Documents"), docPK.ToString() + "_" + fileName); sPath = doc.FilePath; //save db db.SaveChanges(); //save physical file DocFile.SaveAs(sPath); //add document to Lucene-Index LuceneService.Lucene._addToLuceneIndex(sPath); LuceneService.Lucene.Optimize(); db.Refresh(RefreshMode.ClientWins, db.Documents); //send protocoll to users if doc.type is 'prototcol' & checkbox 'send protos' is checked bool mailProto = Convert.ToBoolean(Request["MailProto"].Contains("true")); if (mailProto && documents.SelectedTypeValue == 5) { int s = SendProtos(docPK, documents.SelectedGroupValue ?? 0, fileName); TempData["Success"] = "Das Dokument wurde erfasst & Anzahl versendet: " + s; return(RedirectToAction("ListAll")); //if (sendProtos(docPK, documents.SelectedGroupValue ?? 0)) //{ // TempData["Success"] = "Das Dokument wurde erfasst & versendet"; // return RedirectToAction("ListAll"); //} //TempData["Success"] = "Dokument wurde erfasst, Fehler beim Email-Versand"; //return RedirectToAction("ListAll"); } } TempData["Success"] = "Das Dokument wurde erfasst"; return(RedirectToAction("ListAll")); } catch (Exception ex) { TempData["Success"] = "Fehler beim Erfassen: " + ex.Message; return(RedirectToAction("ListAll")); } }