public async Task Handle(MeasureAdded message, IMessageHandlerContext context) { float isBMIUpdated = await _subscriberService.UpdateBMIAsync(message); log.Info($"in Subscriber Saga, got measure/ id: {message.MeasureId}"); if (isBMIUpdated != -1) { subscriber.Comment = "BMI updated. "; Data.IsBMIUpdated = true; BMIUpdated bMIUpdated = new BMIUpdated { MeasureId = message.MeasureId, BMI = isBMIUpdated, CardId = message.CardId, Weight = message.Weight }; await context.Publish(bMIUpdated); } else { subscriber.Comment = "update BMI failed. "; //send to error queue Data.IsBMIUpdated = false; } await ProcessOrder(context); }
public async Task <float> UpdateBMIAsync(MeasureAdded message) { CardEntity card = await _weightWatchersContext.Card .FirstOrDefaultAsync(c => c.Id == message.CardId); card.BMI = message.Weight / (card.Height * card.Height); card.UpdateDate = DateTime.Now; card.Weight = message.Weight; await _weightWatchersContext.SaveChangesAsync(); return(card.BMI); }
public async Task <float> UpdateBMIAsync(MeasureAdded message) { bool isCardExist = await _subscriberRepository.CardExistAsync(message.CardId); if (isCardExist) { var bmi = await _subscriberRepository.UpdateBMIAsync(message); return(bmi); } return(-1); }
public async Task <ActionResult> AddMeasureAsync([FromBody] MeasureDTO measureDTO) { MeasureModel measureModel = _mapper.Map <MeasureModel>(measureDTO); int measureId = await _measureService.AddMeasureAsync(measureModel); MeasureAdded measureAdded = new MeasureAdded { MeasureId = measureId, CardId = measureModel.CardId, Weight = measureModel.Weight }; await _messageSession.Publish(measureAdded) .ConfigureAwait(false); return(Ok("הפעולה נקלטה בהצלחה!")); }
/// <summary> /// Raise the event (useful for child classes). /// </summary> protected void RaiseMeasureAdded() { MeasureAdded?.Invoke(this, EventArgs.Empty); }