public void AddDocument_OnSave_AddsToRepository() { _documentService.AddDocument(new BasicMappedWebpage { Site = CurrentSite }); Session.QueryOver <Document>().RowCount().Should().Be(1); }
public IActionResult Add(int searchId, string name, string notes, IFormFile uploadedFile) { var document = new Document { SearchId = searchId, Name = name }; documentService.AddDocument(document); documentService.SaveChanges(); var user = Models.User.PrincipalToUser(User); var revision = new Revision { DocumentId = document.Id, Number = 1, AuthorId = user.Id, Notes = notes, File = Models.File.FromUploadedFile(uploadedFile, user.Id) }; document.Revisions.Add(revision); document.LatestRevision = revision; documentService.SaveChanges(); logger.LogInformation("{username} created document {documentId}", user.Username, document.Id); return(Redirect($"View/{document.Id}")); }
//[ValidateAntiForgeryToken] public ActionResult AddProject(Project item) { string name = "", type = "", content = ""; if (ModelState.IsValid) { item.DateCreated = DateTime.Now; item.Name = item.Name.Replace(' ', '_'); _service.AddProject(item); var doc = new Document(); doc.ProjectID = item.ID; doc.DateCreated = item.DateCreated; doc.CreatedBy = _service.GetUserNameByUserID(item.OwnerID); doc.LastUpdatedBy = doc.CreatedBy; InstanceCorrectFile(item.ProjectType, ref name, ref type, ref content); doc.Name = name; doc.Type = type; doc.Content = content; //doc.CreatedBy = _service._db.AppUsers. _documentService.AddDocument(doc); ViewBag.UserName = User.Identity.GetUserName(); var html = RenderRazorViewToString("AddProjectContainerForAdd", item); return(Json(html)); } return(Json(new { success = false })); }
public void TestAddDocumentFail() { // Arrange: var document3 = new Document { ID = 3, Name = "Document3", Type = "CSS", CreatedBy = "User1", DateCreated = new DateTime(2017, 1, 1), Content = "Some Content", LastUpdatedBy = null, ProjectID = 1 }; var mockContext = new MockDataContext(); _DocumentService = new DocumentService(mockContext); mockContext.SaveSuccess = false; // Act: var added = _DocumentService.AddDocument(document3); // Assert: Assert.IsFalse(added); }
public IHttpActionResult Add(Documnet document) { byte[] data = Convert.FromBase64String(document.Data.Split(',').Last()); var str = Encoding.UTF8.GetString(data); var g = Guid.NewGuid(); document.Name = g.ToString() + document.Name; var filePath = Path.Combine(root, document.Name); File.WriteAllBytes(filePath, data); DocumentService.AddDocument(document.Name, "DRAFT", "1.0"); var result = DocumentParserService.DetermineFlowType(filePath); return(Ok()); }
public ActionResult Insert(DocumentManagement entity) { if (ModelState.IsValid) { entity.CreatedBy = GetCurrentUserName(); entity.CreatedDate = DateTime.Now; _docService.AddDocument(entity); _docService.Save(); this.GetCmp <Window>("windowDocumentManagement").Hide(); this.GetCmp <Store>("storeDocumentManagement").Reload(); return(this.Direct()); } return(this.Direct()); }
public ActionResult Create(string fileName, string fileType, int projectID) { var creator = User.Identity.Name; if (string.IsNullOrEmpty(fileName) && string.IsNullOrEmpty(fileType)) { return(Json(new { success = "bothempty" })); } else if (string.IsNullOrEmpty(fileName)) { return(Json(new { success = "nameempty" })); } else if (string.IsNullOrEmpty(fileType)) { return(Json(new { success = "filetypeempty" })); } else { if (fileType[0] != '.') { fileType = "." + fileType; } var newDocument = new Document(); newDocument.Name = fileName.Replace(' ', '_'); newDocument.Type = fileType; newDocument.ProjectID = projectID; newDocument.LastUpdatedBy = creator; newDocument.DateCreated = DateTime.Now; newDocument.CreatedBy = creator; newDocument.Content = ""; if (_service.AddDocument(newDocument)) { var html = RenderRazorViewToString("AddDocumentContainer", newDocument); return(Json(new { html, newDocument.Name, newDocument.Type })); } } return(Json(new { success = false })); }
public void TestAddDocumentSuccess() { // Arrange: var document3 = new Document { ID = 3, Name = "Document3", Type = "CSS", CreatedBy = "User1", DateCreated = new DateTime(2017, 1, 1), Content = "Some Content", LastUpdatedBy = null, ProjectID = 1 }; // Act: var added = _DocumentService.AddDocument(document3); var document = _DocumentService.GetDocumentByID(3); // Assert: Assert.AreEqual(true, added); Assert.AreEqual(3, document.ID); Assert.AreEqual("Document3", document.Name); Assert.AreEqual("Some Content", document.Content); }
public IActionResult AddDocument([FromBody] Document document, [FromBody] byte[] file) { // TODO : Check add permission, save document in repository, check date time issue return(Execute(() => Ok(_documentService.AddDocument(document, file)))); }