Exemplo n.º 1
0
        public IActionResult DeleteAndCreate()
        {
            using var context = contextFactory.Create();
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            return(Ok("Готово, хозяин!"));
        }
        public void Index(TType obj)
        {
            var record = CreateRecord(obj);

            using var context = contextFactory.Create();

            var dbRecord = context.GeolocationIndices.SingleOrDefault(x => x.TargetId == record.TargetId &&
                                                                      x.TargetType == record.TargetType);

            if (record.Geolocations == null)
            {
                if (dbRecord != null)
                {
                    context.GeolocationIndices.Remove(dbRecord);
                }
            }
            else
            {
                if (dbRecord != null)
                {
                    dbRecord.Geolocations = record.Geolocations;
                }
                else
                {
                    context.GeolocationIndices.Add(record);
                }
            }

            context.SaveChanges();
        }
Exemplo n.º 3
0
        public IActionResult SearchServices([FromQuery] string?q)
        {
            if (string.IsNullOrWhiteSpace(q))
            {
                return(BadRequest($"{nameof(q)} should not be null or white space"));
            }

            using var context = contextFactory.Create();

            var serviceIds = context.SearchIndices
                             .Where(x => x.TargetType == TargetTypeEnum.Service && x.Value != null)
                             .AsEnumerable()
                             .Where(x => Match(x.Value, q))
                             .Select(x => x.TargetId)
                             .ToArray();

            return(Ok(servicesRepository.FindByIds(serviceIds)));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Внедрение зависимостей приложения
        /// </summary>
        /// <param name="services">описание сервисов</param>
        /// <param name="configuration">настройки</param>
        public static void InjectDependencies(IServiceCollection services, IConfiguration configuration)
        {
            var mappingConfig = new MapperConfiguration(mc => {
                mc.AddProfile(new MappingProfile());
            });
            var mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            services.AddSingleton(opt => RepositoryContextFactory.Create(configuration));
            services.AddScoped <IOrdersRepository, OrdersRepository>();
            services.AddScoped <IOrdersManager, OrdersManager>();
        }
Exemplo n.º 5
0
        public void Index(TType obj)
        {
            var records = GetRecords(obj);

            if (records.Any())
            {
                using var context = contextFactory.Create();

                foreach (var record in records)
                {
                    var dbRecord = context.SearchIndices.SingleOrDefault(x => x.TargetId == record.TargetId &&
                                                                         x.TargetType == record.TargetType &&
                                                                         x.ValueType == record.ValueType);

                    if (record.Value == null)
                    {
                        if (dbRecord != null)
                        {
                            context.SearchIndices.Remove(dbRecord);
                        }
                    }
                    else
                    {
                        if (dbRecord != null)
                        {
                            dbRecord.Value = record.Value;
                        }
                        else
                        {
                            context.SearchIndices.Add(record);
                        }
                    }
                }

                context.SaveChanges();
            }
        }