public ActionResult Create(DocumentEditModel model) { if (!ModelState.IsValid) { return(View(model)); } Folder parent = null; if (model.ParentId.HasValue) { parent = folderRepository.Load(model.ParentId.Value); } var doc = new Document { Name = model.Name, CreationDate = DateTime.Now, Parent = parent, Avatar = model.Avatar != null && model.Avatar.InputStream != null? model.Avatar.InputStream.ToByteArray() : null }; documentRepository.Save(doc); return(RedirectToAction("Index", "Folder", new { parent = model.ParentId })); }
public ActionResult CreateDocument(DocumentEditModel model) { if (!ModelState.IsValid) { return(View(model)); } Folder parent = null; if (model.ParentId.HasValue) { parent = folderRepository.Load(model.ParentId.Value); } var document = new Document { Name = model.Name, CreationDate = DateTime.Now, Parent = parent, Type = model.Type, Text = model.Text }; documentRepository.Save(document); return(RedirectToAction("Index", new { parent = model.ParentId })); }
public async Task <IActionResult> DocumentEdit(DocumentEditModel model) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(User); model.UpdatedOn = DateTime.Now; model.UpdatedBy = user.FullName; try { var document = _mapper.Map <DocumentEditModel, DocumentDTO>(model); await _documents.Edit(document); } catch (Exception e) { Console.WriteLine(e.Message); } } CreateSelectLists(); // Отображаем ошибки операции foreach (var state in ModelState.Values) { foreach (var error in state.Errors) { this.AddAlertDanger(error.ErrorMessage); } } return(PartialView("_DocumentEdit", model)); }
public IActionResult DocumentEdit(int id) { var document = _documents.GetDocumentById(id); var model = new DocumentEditModel { Id = document.Id, Year = document.Contract.Year, ContractNumber = document.Contract.ContractNumber, ClientName = document.Client.Name, ExploitationPlace = document.Client.ExploitationPlace, DeviceName = document.Device.Name, DeviceType = document.Device.Type, SerialNumber = document.Device.SerialNumber, RegistrationNumber = document.Device.RegistrationNumber, VerificationMethodic = document.Device.VerificationMethodic?.FileName, DocumentNumber = document.DocumentNumber, DocumentType = (document is CertificateDTO) ? DocumentType.Certificate : DocumentType.FailureNotification, CalibrationDate = (document as CertificateDTO)?.CalibrationDate, CalibrationExpireDate = (document as CertificateDTO)?.CalibrationExpireDate, DocumentDate = (document as FailureNotificationDTO)?.DocumentDate, FilePath = Path.Combine("/documentsFolder", document.DocumentFile.Path) }; CreateSelectLists(); return(PartialView("_DocumentEdit", model)); }
public ActionResult Create(long?parent) { var docModel = new DocumentEditModel { ParentId = parent }; return(View(docModel)); }
public async Task <IActionResult> Edit(DocumentEditModel model) { if (!await this.documentsService.DoesItExist(model.DocumentId)) { return(this.NotFound()); } await this.documentsService.EditDocumentContentAsync(model); return(this.RedirectToAction("Index", "Document")); }
public async Task EditDocumentContentAsync(DocumentEditModel model) { var document = await this.documentsRepository .All() .Where(x => x.Id == model.DocumentId) .FirstOrDefaultAsync(); document.Content = new HtmlSanitizer().Sanitize(model.Content); await this.documentsRepository.SaveChangesAsync(); }
public ActionResult New() { var newDocument = new DocumentEditModel() { Document = null, ClientsList = _context.Clients.ToList(), ArticlesList = null, ProductList = _context.Products.ToList() }; return(View("New", newDocument)); }
public async Task EditDocumentContentEditsTheContent() { var model = new DocumentEditModel { DocumentId = this.testDocument1.Id, Title = this.testDocument1.Title, Content = "New Content Here :)", }; await this.service.EditDocumentContentAsync(model); var isSuccess = this.testDocument1.Content == model.Content; Assert.True(isSuccess); }
public async Task EditDocumentContentSanitizesTheContent() { var model = new DocumentEditModel { DocumentId = this.testDocument1.Id, Title = this.testDocument1.Title, Content = "<script>alert(\"Ohh you got destroyed\")</script>" + " <p>New Content Here :)</p>", }; await this.service.EditDocumentContentAsync(model); var isSuccess = !this.testDocument1.Content.Contains("<script>") && this.testDocument1.Content.Contains("<p>"); Assert.True(isSuccess); }
public ActionResult Edit(int id) { var document = _context.Documents.SingleOrDefault(p => p.Id == id); var articles = GetArticles().Where(a => a.DocumentId == id).ToList(); var clients = _context.Clients.ToList(); var products = _context.Products.ToList(); if (document == null) { return(View("ErrorPage", id)); } var viewModel = new DocumentEditModel() { Document = document, ClientsList = clients, ArticlesList = articles, ProductList = products }; return(View("Edit", viewModel)); }