Exemple #1
0
        private async Task <List <DepartmentData> > GetDepartmentAsync(Guid newsId, List <string> errors)
        {
            try
            {
                Response <IOperationResult <IGetDepartmentsResponse> > response =
                    await _rcGetDepartments.GetResponse <IOperationResult <IGetDepartmentsResponse> >(
                        IGetDepartmentsRequest.CreateObj(newsIds: new List <Guid> {
                    newsId
                }));

                if (response.Message.IsSuccess)
                {
                    return(response.Message.Body.Departments);
                }

                _logger.LogWarning(
                    "Error while getting department by news id {NewsId}. Reason:{Errors}",
                    newsId,
                    string.Join('\n', response.Message.Errors));
            }
            catch (Exception exc)
            {
                _logger.LogError("Can not get department by news id {NewsId}. {ErrorsMessage}", exc.Message);
            }

            errors.Add("Can not get department info. Please try again later.");

            return(null);
        }
        private async Task <List <DepartmentData> > GetDepartmentsAsync(List <Guid> newsIds, List <string> errors)
        {
            if (newsIds is null || !newsIds.Any())
            {
                return(null);
            }

            try
            {
                Response <IOperationResult <IGetDepartmentsResponse> > response =
                    await _rcGetDepartments.GetResponse <IOperationResult <IGetDepartmentsResponse> >(
                        IGetDepartmentsRequest.CreateObj(newsIds: newsIds));

                if (response.Message.IsSuccess)
                {
                    return(response.Message.Body.Departments);
                }
                else
                {
                    _logger.LogWarning(
                        "Error while getting departments by news ids: {NewsIds}. Reason:{errors}",
                        string.Join(", ", newsIds),
                        string.Join('\n', response.Message.Errors));
                }
            }
            catch (Exception exc)
            {
                _logger.LogError(
                    "Can not get departments by news ids: {NewsIds}. {ErrorsMessage}",
                    string.Join(", ", newsIds),
                    exc.Message);
            }

            errors.Add("Can not get departments data. Please try again later.");

            return(null);
        }