Exemplo n.º 1
0
        public async Task <IActionResult> Delete(int id, int verId)
        {
            var currentUser = HttpContext.User.Identity.Name;

            //Delete a Document Version, Deleting a complete document is in the Document Metadata Controller
            var meta = _metadataRepository.GetById(id, true, true);

            var ids = string.Format("{0}:{1}", id.ToString(), verId.ToString());

            if (meta == null)
            {
                return(_securityRepository.GateNotFound(currentUser, AccessLogAction.DocumentVersionDelete, "DocumentVersion", ids));
            }

            if (!_securityRepository.UserIsAuthorisedByBuisnessAreas(HttpContext, AuthActions.Delete, meta.BuisnessArea))
            {
                return(_securityRepository.GateUnathorised(currentUser, AccessLogAction.DocumentVersionDelete, "DocumentVersion", ids));
            }

            var oldVer = meta.Versions.FirstOrDefault(ver => ver.Version == verId);

            if (oldVer.Name == null)
            {
                return(_securityRepository.GateNotFound(currentUser, AccessLogAction.DocumentVersionDelete, "DocumentVersion", ids));
            }

            await _documentRepository.DeleteDocumentVersionAsync(oldVer);

            _logger.Log(LogLevel.Debug, "Document File:'{0}' Deleted By {1}", oldVer.GetServerFileName(), HttpContext.User.Identity.Name);

            _logger.Log(LogLevel.Debug, "Deleteing Document {0} Version {1} for User {2}", meta.Id, oldVer.Version, HttpContext.User.Identity.Name);

            _metadataRepository.DeleteVersion(oldVer);
            _metadataRepository.SaveChanges();

            _securityRepository.LogUserAction(currentUser, AccessLogAction.DocumentVersionDelete, id, "DocumentVersion", true);

            return(Ok());
        }