public ActionResult Display(ViewModel input) { var document = _repository.Find<Document>(input.EntityId); var model = new DocumentViewModel { Document = document, AddEditUrl = UrlContext.GetUrlForAction<DocumentController>(x => x.AddUpdate(null)) + "/" + document.EntityId }; return View(model); }
public ActionResult AddUpdate(ViewModel input) { var document = input.EntityId > 0 ? _repository.Find<Document>(input.EntityId) : new Document(); var categoryItems = _selectListItemService.CreateList<DocumentCategory>(x=>x.Name,x=>x.EntityId,true); var model = new DocumentViewModel { Document = document, DocumentCategoryList =categoryItems }; return View(model); }
public ActionResult Save(DocumentViewModel input) { var coId = _httpContextAbstractor.GetCompanyIdFromIdentity(); var document = input.Document.EntityId > 0 ? _repository.Find<Document>(input.Document.EntityId) : new Document(); var newDoc = mapToDomain(input, document); var serverDirectory = "/CustomerDocuments/" + coId; document.FileUrl = _uploadedFileHandlerService.GetUploadedFileUrl(serverDirectory, document.Name); var crudManager = _saveEntityService.ProcessSave(newDoc); if (input.From == "Field") { var field = _repository.Find<Field>(input.ParentId); field.AddDocument(document); crudManager = _saveEntityService.ProcessSave(field, crudManager); } crudManager = _uploadedFileHandlerService.SaveUploadedFile(serverDirectory, newDoc.Name, crudManager); var notification = crudManager.Finish(); return Json(notification, "text/plain"); }
public ActionResult Save(DocumentViewModel input) { var coId = _httpContextAbstractor.GetCompanyIdFromIdentity(); var document = input.Document.EntityId > 0 ? _repository.Find <Document>(input.Document.EntityId) : new Document(); var newDoc = mapToDomain(input, document); var serverDirectory = "/CustomerDocuments/" + coId; document.FileUrl = _uploadedFileHandlerService.GetUploadedFileUrl(serverDirectory, document.Name); var crudManager = _saveEntityService.ProcessSave(newDoc); if (input.From == "Field") { var field = _repository.Find <Field>(input.ParentId); field.AddDocument(document); crudManager = _saveEntityService.ProcessSave(field, crudManager); } crudManager = _uploadedFileHandlerService.SaveUploadedFile(serverDirectory, newDoc.Name, crudManager); var notification = crudManager.Finish(); return(Json(notification, "text/plain")); }
private Document mapToDomain(DocumentViewModel input, Document document) { var documentModel = input.Document; document.FileType = documentModel.FileType; document.Name = documentModel.Name; document.Description = documentModel.Description; if (document.DocumentCategory == null || document.DocumentCategory.EntityId != input.Document.DocumentCategory.EntityId) { document.DocumentCategory = _repository.Find<DocumentCategory>(input.Document.DocumentCategory.EntityId); } return document; }