public HttpResponseMessage AddDiscountPromotion(PromotionDiscountInputDTO promotion) { Guid promotionIntegrationCode = Guid.NewGuid(); if (ModelState.IsValid) { try { //Criacao de promocao sera uma operacao critica. Imaginemos o Facilitador na rua usando o APP. Tem de ser tolerante a falha e baseado no processamento de comando Claims claims = new Claims().Values(); promotion.UserSystemId = claims.userSystemId; promotion.PotencialDemand = _PersonDao.GetAmountCostumersNearby(promotion.PersonIntegrationCode, promotion.ExpertiseId); AddDiscountPromotionCommand command = new AddDiscountPromotionCommand(); command.PromotionMethodPaymentId = promotion.PromotionMethodPaymentId; command.PromotionIntegrationCode = promotion.PromotionIntegrationCode == Guid.Empty ? promotionIntegrationCode : promotion.PromotionIntegrationCode; command.PersonIntegrationCode = promotion.PersonIntegrationCode; command.PersonId = promotion.PersonId; command.ExpertiseId = promotion.ExpertiseId; command.Title = promotion.Title; command.ShortDescription = promotion.ShortDescription; command.StartDateUTC = promotion.StartDateUTC; command.ValidUntilUTC = promotion.ValidUntilUTC; command.RequiredTimeForActivation = (short)promotion.RequiredTimeForActivation; command.PromotionBillingModelId = promotion.PromotionBillingModelId; command.PromotionRecurrenceId = promotion.PromotionRecurrenceId; command.DiscountePercentege = promotion.DiscountePercentege; command.PromotionPaymentTypeId = promotion.PromotionPaymentTypeId; command.NormalPrice = promotion.NormalPrice; command.PromotionalPrice = promotion.PromotionalPrice; command.NumberOfAvailableCoupons = promotion.NumberOfAvailableCoupons; command.CurrencyId = promotion.CurrencyId; command.NeighbourhoodId = promotion.NeighbourhoodId; command.PotencialDemand = promotion.PotencialDemand; command.UserSessionId = promotion.UserSessionId; command.ShortDescription = promotion.ShortDescription; command.UserSystemId = promotion.UserSystemId; command.PromotionMethodPaymentId = promotion.PromotionMethodPaymentId; bus.Send(command); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } } return(Request.CreateResponse(HttpStatusCode.OK, promotionIntegrationCode)); }
public void Handle(AddDiscountPromotionCommand command) { PromotionDiscountInputDTO promotion = new PromotionDiscountInputDTO() { CurrencyId = command.CurrencyId, DiscountePercentege = command.DiscountePercentege, ExpertiseId = command.ExpertiseId, NeighbourhoodId = command.NeighbourhoodId, NormalPrice = command.NormalPrice, NumberOfAvailableCoupons = command.NumberOfAvailableCoupons, PersonId = command.PersonId, PersonIntegrationCode = command.PersonIntegrationCode, PotencialDemand = command.PotencialDemand, PromotionalPrice = command.PromotionalPrice, PromotionBillingModelId = command.PromotionBillingModelId, PromotionIntegrationCode = command.PromotionIntegrationCode, PromotionPaymentTypeId = command.PromotionPaymentTypeId, PromotionRecurrenceId = command.PromotionRecurrenceId, RequiredTimeForActivation = command.RequiredTimeForActivation, ShortDescription = command.ShortDescription, StartDateUTC = command.StartDateUTC, Title = command.Title, UserSessionId = command.UserSessionId, UserSystemId = command.UserSystemId, ValidUntilUTC = command.ValidUntilUTC, PromotionMethodPaymentId = command.PromotionMethodPaymentId }; var _clientPromotion = new HttpClient(); _clientPromotion.BaseAddress = new Uri(CustomConfiguration.WebApiPromotion); var resultTask = _clientPromotion.PostAsJsonAsync("api/Promotion/AddDiscountPromotion", promotion).Result; if (!resultTask.IsSuccessStatusCode) { LogManager.Error("Failure creating a new Promotion. Status: " + resultTask.StatusCode); throw new Exception("Failure creating a new Promotion. Status: " + resultTask.StatusCode); } }