public IActionResult Offer(int Id, [FromBody] OfferResource resource)
        {
            var offer  = repo.GetById(Id);
            var result = mapper.Map <OfferResource, OfferModel>(resource, offer);

            uow.Save();
            return(Ok(result));
        }
        public IActionResult Offer(OfferResource resource)
        {
            var offer = mapper.Map <OfferResource, OfferModel>(resource);

            repo.Add(offer);
            uow.Save();
            var result = mapper.Map <OfferModel, OfferResource>(offer);

            return(Ok(result));
        }
        public async IAsyncEnumerable <OfferResource <Consumable> > QueryOffersAsync(Consumable con, string region)
        {
            NullCheck.ThrowIfNull <Consumable>(con);

            var consumable        = new ConsumableEntity().Build(con);
            var maxDistance       = con.kilometer;
            var consumableAddress = con.address;
            var location          = new AddressEntity().build(consumableAddress);

            _addressMaker.SetCoordinates(location);

            var query = from o in _context.offer as IQueryable <OfferEntity>
                        join c in _context.consumable on o.id equals c.offer_id
                        join ap in _context.address on o.address_id equals ap.Id
                        where consumable.category == c.category && !c.is_deleted && o.region == region
                        select new { o, c, ap };

            if (!string.IsNullOrEmpty(consumable.name))
            {
                query = query.Where(collection => consumable.name == collection.c.name);
            }
            if (!string.IsNullOrEmpty(consumable.manufacturer))
            {
                query = query.Where(collection => consumable.manufacturer == collection.c.manufacturer);;
            }
            if (consumable.amount > 0)
            {
                query = query.Where(collection => consumable.amount <= collection.c.amount);
            }

            List <OfferResource <Consumable> > resources = new List <OfferResource <Consumable> >();
            var results = await query.ToListAsync();

            foreach (var data in results)
            {
                var resource = new Consumable().build(data.c);

                var yLatitude  = data.ap.Latitude;
                var yLongitude = data.ap.Longitude;
                var distance   = DistanceCalculator.computeDistance(location.Latitude, location.Longitude, yLatitude, yLongitude);
                if (distance > maxDistance && maxDistance != 0)
                {
                    continue;
                }
                resource.kilometer = (int)Math.Round(distance);

                var provider        = new Provider().Build(data.o);
                var providerAddress = new Address().Build(data.ap);

                provider.address = providerAddress;

                var offer = new OfferResource <Consumable>()
                {
                    resource = resource
                };

                // ---- HOTFIX
                // Vorerst sollen keine persönliche Daten veröffentlicht werden.
                provider.ispublic = false;
                // ---- END HOTFIX

                if (provider.ispublic)
                {
                    offer.provider = provider;
                }

                yield return(offer);
            }
        }
        public async IAsyncEnumerable <OfferResource <Personal> > QueryOffersAsync(Manpower manpower, string region)
        {
            NullCheck.ThrowIfNull <Manpower>(manpower);

            var maxDistance     = manpower.kilometer;
            var manpowerAddress = manpower.address;
            var location        = new AddressEntity().build(manpowerAddress);

            _addressMaker.SetCoordinates(location);

            var query = from o in _context.offer as IQueryable <OfferEntity>
                        join personal in _context.personal on o.id equals personal.offer_id
                        join ap in _context.address on o.address_id equals ap.Id
                        where !personal.is_deleted && o.region == region
                        select new { o, personal, ap };

            if (!string.IsNullOrEmpty(manpower.institution))
            {
                query = query.Where(collection => manpower.institution == collection.personal.institution);;
            }

            if (manpower.qualification.Any())
            {
                query = query.Where(collection => manpower.qualification.Contains(collection.personal.qualification));
            }
            if (manpower.area.Any())
            {
                query = query.Where(collection => manpower.area.Contains(collection.personal.area));
            }

            if (!string.IsNullOrEmpty(manpower.researchgroup))
            {
                query = query.Where(collection => manpower.researchgroup == collection.personal.researchgroup);;
            }
            if (manpower.experience_rt_pcr)
            {
                query = query.Where(collection => collection.personal.experience_rt_pcr);;
            }

            List <OfferResource <Personal> > resources = new List <OfferResource <Personal> >();
            var results = await query.ToListAsync();

            foreach (var data in results)
            {
                var resource = new Personal().build(data.personal);

                var yLatitude  = data.ap.Latitude;
                var yLongitude = data.ap.Longitude;
                var distance   = DistanceCalculator.computeDistance(location.Latitude, location.Longitude, yLatitude, yLongitude);
                if (distance > maxDistance && maxDistance != 0)
                {
                    continue;
                }
                resource.kilometer = (int)Math.Round(distance);

                var provider        = new Provider().Build(data.o);
                var providerAddress = new Address().Build(data.ap);

                provider.address = providerAddress;

                var offer = new OfferResource <Personal>()
                {
                    resource = resource
                };

                // ---- HOTFIX
                // Vorerst sollen keine persönliche Daten veröffentlicht werden.
                provider.ispublic = false;
                // ---- END HOTFIX

                if (provider.ispublic)
                {
                    offer.provider = provider;
                }

                yield return(offer);
            }
        }