public async Task <IActionResult> FinPaypalCart([FromBody] PaymentTransactionDto payment) { if (payment.UserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var cartItems = await _repo.GetCartItems(payment.UserId); //var returnCart = _mapper.Map<IEnumerable<PayPalCart>>(cartItems); PaypalTransaction transaction = new PaypalTransaction(); transaction.Intent = payment.Info.Intent; transaction.OrderID = payment.Info.OrderID; transaction.PayerID = payment.Info.PayerID; transaction.PaymentID = payment.Info.PaymentID; transaction.PaymentToken = payment.Info.PaymentToken; transaction.UserId = payment.UserId; transaction.User = await _repo.GetUser(payment.UserId); transaction.Items = _repo.GetItemsFormCart(payment.UserId); _repo.Add(transaction); foreach (Cart cart in cartItems) { var item = _repo.GetItem(cart.Item.Id); item.Result.Quantity = item.Result.Quantity - cart.Quantity; _repo.Delete(cart); } if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception("Failed to delete item from your cart."); }
public static CookieTransactionDto CreateCookieTransaction(CookieTransaction cookieTransaction) { CookieTransactionDto ret = null; var typeSwitch = new TypeSwitch() .Case((OrderTransaction x) => ret = new OrderTransactionDto() { Cookies = x.Cookies.Select(c => new CookieQuantityDto() { Cookie = new CookieDto() { CookieVariety = c.Cookie.Variety.ToString(), Price = c.Cookie.Price }, Quantity = c.Quantity, } ).ToList(), DateEntered = x.DateEntered.ToLocalTime(), DateReceived = x.DateReceived.ToLocalTime() }) .Case((CookieTransferInTransaction x) => ret = new CookieTransferInTransactionDto() { DateEntered = x.DateEntered.ToLocalTime(), DateReceived = x.DateReceived.ToLocalTime(), FromInventoryId = x.FromInventoryId, Cookies = x.Cookies.Select(c => new CookieQuantityDto() { Cookie = new CookieDto() { CookieVariety = c.Cookie.Variety.ToString(), Price = c.Cookie.Price }, Quantity = c.Quantity, } ).ToList() }) .Case((CookieTransferOutTransaction x) => ret = new CookieTransferOutTransactionDto() { DateEntered = x.DateEntered.ToLocalTime(), DateReceived = x.DateReceived.ToLocalTime(), ToInventoryId = x.ToInventoryId, Cookies = x.Cookies.Select(c => new CookieQuantityDto() { Cookie = new CookieDto() { CookieVariety = c.Cookie.Variety.ToString(), Price = c.Cookie.Price }, Quantity = c.Quantity, } ).ToList() }) .Case((PaymentTransaction x) => ret = new PaymentTransactionDto() { DateEntered = x.DateEntered.ToLocalTime(), DateReceived = x.DateReceived.ToLocalTime(), Amount = x.Amount, }) .Case((UpdateCookiesTransaction x) => ret = new UpdateCookiesTransactionDto() { DateEntered = x.DateEntered, DateReceived = x.DateReceived, Cookies = x.Cookies.Select(c => new CookieQuantityDto() { Cookie = new CookieDto() { CookieVariety = c.Cookie.Variety.ToString(), Price = c.Cookie.Price }, Quantity = c.Quantity, } ).ToList() }); typeSwitch.Switch(cookieTransaction); return(ret); }