Exemplo n.º 1
0
        public async Task <LanguageCreateResponse> CreateLanguage(LanguageCreateRequest request)
        {
            var response = new LanguageCreateResponse();

            var currentUser = _cacheManager.GetCachedUser(request.CurrentUserId);

            if (!currentUser.IsSuperAdmin)
            {
                response.SetInvalid();
                return(response);
            }

            var trimName = request.Name.Trim();
            var result   = await _languageRepository.Any(x => x.Name == trimName ||
                                                         x.IsoCode2Char == request.IsoCode2 ||
                                                         x.IsoCode3Char == request.IsoCode3);

            if (result)
            {
                response.ErrorMessages.Add("language_name_must_be_unique");
                response.Status = ResponseStatus.Invalid;
                return(response);
            }

            var entity = _languageFactory.CreateEntityFromRequest(request);
            var id     = await _languageRepository.Insert(request.CurrentUserId, entity);

            if (id > 0)
            {
                response.Item   = _languageFactory.CreateDtoFromEntity(entity);
                response.Status = ResponseStatus.Success;
                return(response);
            }

            response.SetFailed();
            return(response);
        }