Example #1
0
        public async Task <LanguageReadListResponse> GetLanguages(LanguageReadListRequest request)
        {
            var response = new LanguageReadListResponse();

            Expression <Func <Language, object> > orderByColumn = x => x.Id;

            Expression <Func <Language, bool> > filter = null;

            if (request.SearchTerm.IsNotEmpty())
            {
                filter = x => x.Name.Contains(request.SearchTerm) ||
                         x.IsoCode2Char.Contains(request.SearchTerm) ||
                         x.IsoCode3Char.Contains(request.SearchTerm) ||
                         x.OriginalName.Contains(request.SearchTerm);
            }

            List <Language> entities;

            if (request.PagingInfo.Skip < 1)
            {
                entities = await _languageRepository.SelectAfter(filter, request.PagingInfo.LastUid, request.PagingInfo.Take, orderByColumn, request.PagingInfo.IsAscending);
            }
            else
            {
                entities = await _languageRepository.SelectMany(filter, request.PagingInfo.Skip, request.PagingInfo.Take, orderByColumn, request.PagingInfo.IsAscending);
            }

            if (entities != null)
            {
                for (var i = 0; i < entities.Count; i++)
                {
                    var entity = entities[i];
                    var dto    = _languageFactory.CreateDtoFromEntity(entity);
                    response.Items.Add(dto);
                }
            }

            response.PagingInfo.Skip           = request.PagingInfo.Skip;
            response.PagingInfo.Take           = request.PagingInfo.Take;
            response.PagingInfo.LastUid        = request.PagingInfo.LastUid;
            response.PagingInfo.IsAscending    = request.PagingInfo.IsAscending;
            response.PagingInfo.TotalItemCount = await _languageRepository.Count(filter);

            response.Status = ResponseStatus.Success;
            return(response);
        }
        public bool Delete(Guid id, Guid countryId)
        {
            try
            {
                if (_repository.Count(countryId) > NUMBER_OF_LANGUAGES_REQUIRED_PER_COUNTRY)
                {
                    _repository.Delete(id);
                }
                else
                {
                    _logger.LogError(LOCALIZATION_LANGUAGE_LAST);
                    throw new Exception(LOCALIZATION_LANGUAGE_LAST);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Exception while deleting language : {0} - {1} ", ex.StackTrace, ex.Message);
                return(false);
            }

            return(true);
        }