public async Task <IActionResult> Buy(ItemOrderModel model) { var item = _repository.GetItem(model.ItemId); var buyerCurrencyRate = _userRepository.UserCurrencyRate(User.Identity.Name); var buyerPrice = Decimal.Round(item.Price / item.User.Country.Currency.Rate * buyerCurrencyRate, 2); if (_orderRepository.PlaceOrder(model.ItemId, buyerPrice, model.BuyerName, model.Qty, model.Status)) { var buyer = _userRepository.FindUserByName(model.BuyerName); var MessageForSeller = $"Buyer {buyer.Name} with email {buyer.Email} has purchased item {item.Name}. Please contact him"; var MessageForBuyer = $"You have placed new order for item {item.Name} from {item.User.Name} whos email is {item.User.Email} In urgent cases you can email to seller"; await _messageService.SendMessageAsync("email", MessageForSeller, "New order", item.User.Email); // message to seller await _messageService.SendMessageAsync("email", MessageForBuyer, "Order confirmation", buyer.Email); // message to buyer ViewBag.Status = "Order has been placed. Seller will contact you as soon as possible. Please check email"; } else { ViewBag.Status = "Error"; } return(View()); }
public IActionResult ConfirmOrder(int itemId) { var item = _repository.GetItem(itemId); var buyerCurrencyRate = _userRepository.UserCurrencyRate(User.Identity.Name); ItemOrderModel model = new ItemOrderModel(); if (item != null) { model = new ItemOrderModel() { ItemName = item.Name, Price = item.Price * item.User.Country.Currency.Rate / buyerCurrencyRate, BuyerName = User.Identity.Name, ItemId = itemId, SellerName = item.User.Name, PossibleToShipAnotherCountry = item.IsMultiCountryPossible, }; } return(View(model)); }
public IHttpActionResult UpdateItemOrder([FromBody] ItemOrderModel itemOrder) { _itemFacade.UpdateItemOrder(Mapper.Map <List <ItemNamesDto> >(itemOrder.ItemNames)); return(Ok()); }