Пример #1
0
        public async Task <Result <LocalesErrorCodes> > DeleteAsync(string id, string userName, string correlationId)
        {
            var existing = await _localesRepository.GetById(id);

            if (existing.IsFailed)
            {
                return(existing.ToResultWithoutValue());
            }

            if (await _localesRepository.HasAnyLocalizedValues(id))
            {
                return(new Result <LocalesErrorCodes>(LocalesErrorCodes.CannotDeleteLocaleAssignedToAnyLocalizedValue));
            }

            if (existing.Value.IsDefault)
            {
                return(new Result <LocalesErrorCodes>(LocalesErrorCodes.CannotDeleteDefaultLocale));
            }

            var result = await _localesRepository.DeleteAsync(id);

            if (result.IsSuccess)
            {
                await _auditService.TryAudit(correlationId, userName, id, AuditDataType.Locale,
                                             oldStateJson : existing.Value.ToJson());
            }

            return(result);
        }