public async Task <IActionResult> Details() { var buyerId = (await _userManager.GetUserAsync(User)).BuyerId; var buyer = await _buyerManager.GetById(buyerId); var buyerViewModel = _mapper.Map <Buyer, BuyerViewModel>(buyer); return(View(buyerViewModel)); }
public async Task <IActionResult> Buy(PurchaseViewModel purchaseViewModel) { try { var buyerId = (await _userManager.GetUserAsync(User)).BuyerId; var buyer = await _buyerManager.GetById(buyerId); var order = new Order { Amount = purchaseViewModel.Amount, BuyerId = buyer.Id, ProductId = purchaseViewModel.ProductId }; var product = await _productManager.GetById(order.ProductId); product.AmountInStorage -= order.Amount; await _productManager.Update(product); await _orderManager.Add(order); return(RedirectToAction(nameof(Index))); } catch (Exception exception) { _logger.LogError($"Error occured during creating purchase. Exception: {exception.Message}"); return(View(purchaseViewModel)); } }
public async Task <ActionResult> Buy([FromBody] Purchase purchase) { try { var buyerId = (await _userManager.GetUserAsync(User)).BuyerId; var buyer = await _buyerManager.GetById(buyerId); var order = new Order { Amount = purchase.Amount, BuyerId = buyer.Id, ProductId = purchase.ProductId }; var product = await _productManager.GetById(order.ProductId); product.AmountInStorage -= order.Amount; await _productManager.Update(product); await _orderManager.Add(order); return(Ok()); } catch (Exception exception) { _logger.LogError($"Error occured during creating purchase. Exception: {exception.Message}"); return(BadRequest()); } }
private async Task PrintBuyerInformation() { var orderId = ReadId(); var buyerId = (await _orderManager.GetById(orderId)).BuyerId; new List <Buyer> { await _buyerManager.GetById(buyerId) }.WriteCollectionAsTable(); Console.ReadKey(); }
public async Task <ActionResult <Buyer> > Get() { try { var buyerId = int.Parse(User.Claims.FirstOrDefault(claim => claim.Type == BuyerClaim.BuyerId).Value); var buyer = await _buyerManager.GetById(buyerId); return(buyer); } catch (Exception exception) { _logger.LogError($"Error occured during get buyer. Exception: {exception.Message}"); return(BadRequest()); } }