Exemplo n.º 1
0
 public ActionResult Edit(int id, ServiceProvider provider)
 {
     try
     {
         // TODO: Add update logic here
         repo.Update(id, provider);
         return(RedirectToAction(nameof(Index)));
     }
     catch
     {
         return(View());
     }
 }
Exemplo n.º 2
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);
                }
            }
        }