Exemplo n.º 1
0
        public IActionResult Lock(int id)
        {
            string         currentUser = HttpContext.User.Identity.Name;
            MetadataEntity item        = _metadataRepository.GetById(id);

            if (item == null)
            {
                return(_securityRepository.GateNotFound(currentUser, AccessLogAction.DocumentLocked, "Metadata", id.ToString()));
            }

            if (!_securityRepository.UserIsAuthorisedByBuisnessAreas(HttpContext, AuthActions.Update, item.BuisnessArea))
            {
                return(_securityRepository.GateUnathorised(currentUser, AccessLogAction.DocumentLocked, "Metadata", id.ToString()));
            }

            bool success = _metadataRepository.TryLockDocument(ref item, HttpContext);

            if (!success)
            {
                return(_securityRepository.GateCannotLock(currentUser, "Metadata", id.ToString()));
            }

            _metadataRepository.Touch(ref item);

            _logger.Log(LogLevel.Debug, "DocumentMetadata {0} Locked By {1}", item.Id, currentUser);
            _securityRepository.LogUserAction(currentUser, AccessLogAction.DocumentLocked, item.Id.ToString(), "Metadata", true);

            _metadataRepository.SaveChanges();

            return(Ok(success));
        }