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 <IActionResult> UpdateDemand([FromBody] Demand demand)
        {
            // Dictionary<string, object> headers = new Dictionary<string, object>();
            // headers.Add("update", "update");
            // publisher.Publish(JsonConvert.SerializeObject(demand), "demand.update", headers);
            this.PublishEvent("update", "company.demand", demand: demand);
            this.PublishEvent("update", "customer.demand", demand: demand);

            return(Ok(await _repository.Update(demand)));
        }
示例#3
0
        public void Delete(int Id)
        {
            var demand = demandRepository.Find(Id);

            if (demand == null)
            {
                throw new KeyNotFoundException();
            }

            demand.RecordStatus = Helpdesk.Model.Enums.RecordStatus.D;
            demandRepository.Update(demand);
            unitOfWork.SaveChanges();
        }