Exemplo n.º 1
0
        public async Task <ServiceTypeDto> CreateAsync(ServiceTypeCreateDto item)
        {
            if (await _serviceTypeRepository.AnyServiceAsync(x => x.Name == item.Name))
            {
                throw new FieldLogicException($"Service type with name {item.Name} already exists!", nameof(item.Name));
            }

            var service = Mapper.Map <ServiceType>(item);

            _serviceTypeRepository.Create(service);
            await SaveProvider.SaveAsync();

            return(Mapper.Map <ServiceTypeDto>(service));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <ServiceType> > CreateServiceType([FromBody] ServiceType serviceType)
        {
            try
            {
                await _repository.Create(serviceType);

                return(CreatedAtRoute("ServiceType", new { id = serviceType.ServiceTypeId }, serviceType));
            }
            catch (Exception exc)
            {
                _logger.LogError($"Error: {exc}");
                // transaction.Rollback();
                return(NotFound());
            }
        }
Exemplo n.º 3
0
        public void EnsureSeedData(
            IServiceStatusRepository serviceStatusRepository,
            IServiceTypeRepository serviceTypeRepository,
            IServiceProviderRepository serviceProviderRepository,
            IServiceSettings serviceSettings
            )
        {
            PropertyInfo[] properties;

            properties = serviceSettings.ServiceTypeNames.GetType().GetProperties();
            foreach (var property in properties)
            {
                var value = serviceSettings.ServiceTypeNames.GetType()
                            .GetProperty(property.Name)
                            .GetValue(serviceSettings.ServiceTypeNames);

                string typedValue = (string)value;

                if (serviceTypeRepository.GetSingle(x => x.Name.Equals(typedValue)) == null)
                {
                    serviceTypeRepository.Create(new ServiceType {
                        Name = typedValue
                    });
                }
            }

            properties = serviceSettings.ServiceStatusesSettings.GetType().GetProperties();
            foreach (var property in properties)
            {
                var value = serviceSettings.ServiceStatusesSettings.GetType()
                            .GetProperty(property.Name)
                            .GetValue(serviceSettings.ServiceStatusesSettings);

                var typedValue = (ServiceStatusSettings)value;

                var serviceStatus = serviceStatusRepository.GetSingle(x => x.Name.Equals(typedValue.Name));
                if (serviceStatus == null)
                {
                    serviceStatusRepository.Create(new ServiceStatus
                    {
                        Name        = typedValue.Name,
                        Description = typedValue.Description
                    });
                }
                else
                {
                    serviceStatus.Name        = typedValue.Name;
                    serviceStatus.Description = typedValue.Description;
                    serviceStatusRepository.Update(serviceStatus);
                }
            }

            properties = serviceSettings.ServiceProviderTypeSettings.GetType().GetProperties();
            foreach (var property in properties)
            {
                var value = serviceSettings.ServiceProviderTypeSettings.GetType()
                            .GetProperty(property.Name)
                            .GetValue(serviceSettings.ServiceProviderTypeSettings);

                var typedValue = (ServiceProviderSettings)value;

                var serviceProvider = serviceProviderRepository.GetSingle(x => x.Name.Equals(typedValue.Name));
                if (serviceProvider == null)
                {
                    var serviceType = serviceTypeRepository.GetSingle(x => x.Name.Equals(property.Name));
                    if (serviceType == null)
                    {
                        continue;
                    }

                    serviceProviderRepository.Create(new ServiceProvider
                    {
                        Name          = typedValue.Name,
                        Description   = typedValue.Description,
                        WebSite       = typedValue.WebSite,
                        ServiceTypeId = serviceType.Id
                    });
                }
                else
                {
                    serviceProvider.Name        = typedValue.Name;
                    serviceProvider.Description = typedValue.Description;
                    serviceProvider.WebSite     = typedValue.WebSite;
                    serviceProviderRepository.Update(serviceProvider);
                }
            }
        }