Example #1
0
        public async Task AddDocument(Document document, byte[] file)
        {
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document), "Document should not be null");
            }
            await _repository.AddDocument(document, file);

            DocumentAccessHistory accessHistory = GetAccessDetails(document.DocumentId, document.DocumentId, document.CreatedBy, AccessLog.Created);
            await _accessRepository.InsertDocumentAccessLog(accessHistory);
        }
Example #2
0
        public async Task <CreateDocumentCommandResponse> HandleAsync(CreateDocumentCommand request)
        {
            var name = request.Name;
            var text = request.Text;

            var document = _documentFactory.Create(name, text);

            _documentRepository.AddDocument(document);

            await _unitOfWork.SaveChangesAsync();

            return(_mapper.Map <Document, CreateDocumentCommandResponse>(document));
        }
Example #3
0
        public async Task <string> AddDocument(Document document)
        {
            int    insertedmasterdocumentid = 0;
            string filePath = ConfigurationManager.AppSettings["FilePath"];

            filePath = filePath + document.FilePath;
            int inserteddocumentid = await DocumentRepository.AddDocument(new Document { ProjectID = document.ProjectID, GroupID = document.GroupID, DocumentName = document.DocumentName, DocumnetType = document.DocumnetType, FilePath = filePath, Stage = document.Stage, IsAvailable = document.IsAvailable, Completed = document.Completed, IsMaster = document.IsMaster, CreatedDate = document.CreatedDate, CreatedBy = document.CreatedBy });

            if (document.IsMaster == "True")
            {
                insertedmasterdocumentid = await DocumentMasterRepository.AddMasterDocument(new DocumentMaster { Stage = document.Stage, Document = document.DocumentName });
            }

            return(inserteddocumentid != 0 ? "Successfully Insertion of document record" : "Insertion failed");
        }
        public async Task <IActionResult> AddDocument([FromForm] DocumentViewModel model, IFormFile file)
        {
            try
            {
                var user = await _userManager.FindByEmailAsync(model.OwnerUserName);

                var dava     = _davaRepository.GetDava(model.DavaId);
                var document = new Document();
                if (user == null)
                {
                    throw new Exception("Kullanıcı bulunamadı!");
                }
                if (file == null)
                {
                    throw new Exception("Dosya Bulunamadı!");
                }
                if (dava == null)
                {
                    throw new Exception("Dosya ile ilişkilendirilecek dava bulunamadı!");
                }
                var filePath = model.DavaId.ToString() + "-" + model.Date.ToShortDateString() + "-" + Path.GetRandomFileName() + file.FileName;

                var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\documents", filePath);
                using (var stream = new FileStream(path, FileMode.Create))
                {
                    file.CopyToAsync(stream).Wait();
                }
                document.Date        = model.Date;
                document.Description = model.Description;
                document.FileName    = file.FileName;

                document.Dava     = dava;
                document.Owner    = user;
                document.FilePath = filePath;
                document.IsActive = true;

                var doc   = _documentRepository.AddDocument(document);
                var docVM = _mapper.Map <DocumentViewModel>(doc);


                return(Ok(docVM));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        /**
         * Function to be called on Http POST request (api/messages). Attempts to add document
         * to repository. If successfully created, an Http Created message (status code: 201)
         * with a copy of the created document and, in the response header, the location of newly
         * created file is returned to client.
         *
         * Args:
         *  Document item
         *      - The Document to be created
         *
         * Returns:
         *  HttpResponseMessage
         */
        public HttpResponseMessage PostDocument(Document item)
        {
            HttpResponseMessage response;

            item = repository.AddDocument(item);
            if (item != null)
            {
                response = Request.CreateResponse <Document>(HttpStatusCode.Created, item);
                string uri = Url.Link("DefaultApi", new { id = item.ID });
                response.Headers.Location = new Uri(uri);
                repository.ScheduleDeletionTime(item.ID, GetTimeToLive());
            }
            else
            {
                response = Request.CreateResponse <String>(HttpStatusCode.BadRequest,
                                                           "Bad Request: specified document was not able to be created.");
            }
            return(response);
        }
Example #6
0
        public ServiceResponse AddDocument(string docName, byte[] docData, string uploadedFileContentType,
                                           int accessCode)
        {
            Model.Entities.Document.Document doc = new Model.Entities.Document.Document()
            {
                DateAddedOnUtc    = DateTime.Now,
                DateToDeleteByUtc = DateTime.Now.AddMinutes(10),
                DocumentName      = docName,
                DocumentData      = docData,
                AccessCode        = accessCode,
                DocumentType      = uploadedFileContentType
            };
            _iDocumentRepository.AddDocument(doc);
            ServiceResponse submitResponse = _iDocumentRepository.Submit();

            if (submitResponse.WasSuccess)
            {
                submitResponse.Message = "Uploaded Successfully";
            }

            return(submitResponse);
        }
Example #7
0
        public IActionResult Save([Bind("Id,Name,Title,Content")] Document entity, int?page = 1, string keyword = "")
        {
            ViewData["page"]    = $"{page}";
            ViewData["keyword"] = keyword;

            if (ModelState.IsValid)
            {
                var ipAddress = Request.HttpContext.Features.Get <IHttpConnectionFeature>()?.RemoteIpAddress?.ToString();


                if (String.IsNullOrEmpty($"{RouteData.Values["id"]}"))
                {
                    entity.PostDate   = DateTime.Now;
                    entity.PostIp     = ipAddress;
                    entity.ModifyDate = DateTime.Now;
                    entity.ModifyIp   = ipAddress;
                    _repo.AddDocument(entity);
                }
                else
                {
                    var oEntity = _repo.GetDocumentById(entity.Id);

                    //oEntity.PostDate = DateTime.Now;
                    //oEntity.PostIp = ipAddress;

                    oEntity.ModifyDate = DateTime.Now;
                    oEntity.ModifyIp   = ipAddress;
                    oEntity.Title      = entity.Title;
                    oEntity.Name       = entity.Name;
                    oEntity.Content    = entity.Content;

                    _repo.UpdateDocument(oEntity);
                }

                return(RedirectToAction("Detail", new { id = entity.Id, page = page, keyword = keyword }));
            }

            return(View(entity));
        }