private async Task <bool> ProcessOfferAsync(string message, string action)
        {
            switch (action)
            {
            case "create":
                var offer = JsonConvert.DeserializeObject <Offer.API.Entities.Offer>(message);

                var demand = await _repository.GetDemandById(offer.DemandID);

                var offerIDs = demand.OfferIds;

                offerIDs.Add(offer.Id);
                demand.OfferIds = offerIDs;

                await _repository.Update(demand);

                break;

            case "update":

                break;

            case "delete":
                var id = JsonConvert.DeserializeObject <string>(message);

                var demands = await _repository.getDemands();

                foreach (var oneDemand in demands)
                {
                    if (oneDemand.OfferIds.Contains(id))
                    {
                        var demandsOfferIDs = oneDemand.OfferIds;
                        demandsOfferIDs.Remove(id);
                        oneDemand.OfferIds = demandsOfferIDs;

                        await _repository.Update(oneDemand);

                        break;
                    }
                }

                break;

            default:
                break;
            }
            return(true);
        }
Пример #2
0
        public async Task <ActionResult <IEnumerable <Demand> > > GetDemands()
        {
            var demands = await _repository.getDemands();

            return(Ok(demands));
        }