Example #1
0
        public async Task <ActionResult <List <CertificateTypeViewModel> > > GetAllCertificateTypesAsync()
        {
            try
            {
                TaskListResult <CertificateType> result = await certificateService.GetAllCertificateTypesAsync();

                if (!result.Succeeded)
                {
                    return(UnprocessableEntity(new ErrorViewModel {
                        Type = Type.Error, Message = result.Message
                    }));
                }

                if (result.Data.Count == 0)
                {
                    return(Ok(new List <CategoryViewModel>()));
                }

                List <CertificateTypeViewModel> certificateTypeViewModel = result.Data
                                                                           .Select(CertificateTypeViewModel.CreateVm)
                                                                           .ToList();

                return(Ok(certificateTypeViewModel));
            }
            catch (Exception ex)
            {
                string message = GetType().Name + "Error in " + nameof(GetAllCertificateTypesAsync);
                logger.LogError(ex, message);
                return(UnprocessableEntity(new ErrorViewModel {
                    Type = Type.Error, Message = message
                }));
            }
        }