Exemplo n.º 1
0
 public Provider Build(DemandEntity d)
 {
     NullCheck.ThrowIfNull <DemandEntity>(d);
     name         = d.name;
     organisation = d.institution;
     phone        = d.phone;
     mail         = d.mail;
     return(this);
 }
Exemplo n.º 2
0
        public async Task <string> InsertAsync(Demand demand)
        {
            NullCheck.ThrowIfNull <Offer>(demand);
            Provider provider = demand.provider;

            //Build as entities
            DemandEntity demandEntity = new DemandEntity().Build(provider);

            // Store address if available
            if (provider.address != null && provider.address.ContainsInformation())
            {
                AddressEntity demandAddressEntity = new AddressEntity().build(provider.address);
                _addressMaker.SetCoordinates(demandAddressEntity);
                await demandAddressEntity.InsertAsync(_context);

                demandEntity.address_id = demandAddressEntity.Id;
            }

            // Store demand
            demandEntity.created_at_timestamp = DateTime.Now;
            demandEntity.token = CreateToken();
            await demandEntity.InsertAsync(_context);

            var demandId = demandEntity.id;

            // Store resources
            if (demand.consumables != null)
            {
                foreach (Consumable c in demand.consumables)
                {
                    ConsumableDemandEntity entity = new ConsumableDemandEntity().Build(c);
                    entity.demand_id            = demandId;
                    entity.created_at_timestamp = DateTime.Now;
                    await entity.InsertAsync(_context);
                }
            }
            if (demand.devices != null)
            {
                foreach (var d in demand.devices)
                {
                    DeviceDemandEntity entity = new DeviceDemandEntity().Build(d);
                    entity.demand_id            = demandId;
                    entity.created_at_timestamp = DateTime.Now;
                    await entity.InsertAsync(_context);
                }
            }

            return(demandEntity.token);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> ConsumableAnonymousContactAsync([FromBody] ContactInformationDemand contactInformationDemand, int id)
        {
            NullCheck.ThrowIfNull <ContactInformationDemand>(contactInformationDemand);

            try
            {
                _mailInputValidatorService.validateMail(contactInformationDemand.senderEmail);
                ConsumableDemandEntity consumable = await _resourceDemandQueryService.FindAsync(new ConsumableDemandEntity(), id);

                if (consumable is null)
                {
                    return(NotFound(FailureCodes.NotFoundDevice));
                }

                DemandEntity demand = await _resourceDemandQueryService.FindAsync(new DemandEntity(), consumable.demand_id);

                if (demand is null)
                {
                    return(NotFound(FailureCodes.NotFoundOffer));
                }

                var resourceNameDE = _languageDE.Consumable[consumable.category];
                var resourceNameEN = _languageEN.Consumable[consumable.category];

                var mailAddressReceiver  = demand.mail;
                var mailUserNameReceiver = demand.name;
                // TODO
                var region = "de";
                await _mailService.SendOfferMailToDemanderAsync(region, contactInformationDemand, mailAddressReceiver,
                                                                mailUserNameReceiver, resourceNameDE, resourceNameEN);

                await _mailService.SendDemandConformationMailToDemanderAsync(region, contactInformationDemand);

                return(Ok());
            }
            catch (ArgumentException e)
            {
                return(BadRequest(e.Message));
            }
        }