public async Task <IActionResult> Checkout(UserCheckoutCartViewModel model) { if (!ModelState.IsValid) { TempData.AddErrorMessage(string.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage)))); return(View(model)); } try { var cartItems = await GetCurrentUserCartItems(); var purchaseProduct = cartItems .Select(c => new PurchaseProduct { Id = c.Id, PriceAfterDiscount = c.PriceAfterDiscount, }) .ToList(); await _purchaseService.AddPurchase(purchaseProduct, User.Identity.Name, model.Address); } catch (InvalidOperationException ex) { TempData.AddErrorMessage(ex.Message); return(RedirectToAction(nameof(UsersController.Checkout), UsersControllerName)); } TempData.AddSuccessMessage(TempMessages.ThankYouPurchase); return(Redirect(Home)); }
// POST: api/Purchase public IHttpActionResult Post([FromBody] PurchaseDTO dto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _purchaseService.AddPurchase(dto); return(Ok()); }
public IActionResult Purchase(PurchaseModel request) { PurchaseModel model = new PurchaseModel(); List <DDLCategory> categories1 = new List <DDLCategory>(); List <DDLCategory> categories2 = new List <DDLCategory>(); List <Player> playerlist = new List <Player>(); playerlist = _playerService.GetPlayers(); if (playerlist != null && playerlist.Count > 0) { foreach (var item in playerlist) { categories1.Add(new DDLCategory { ID = item.Id, CategoryName = item.Username }); } } List <Card> cardlist = new List <Card>(); cardlist = _cardService.GetCardsByPlayerId(1); if (cardlist != null && cardlist.Count > 0) { foreach (var item in cardlist) { categories2.Add(new DDLCategory { ID = item.Id, CategoryName = item.Number }); } } model.PlayerList = new List <DDLCategory>(); model.PlayerList = categories1; model.Selected_PlayerId = 1; model.CardList = new List <DDLCategory>(); model.CardList = categories2; model.Selected_CardId = 1; Purchase purchase = request.ToEntity(); purchase.Player = _playerService.GetPlayer(request.Selected_PlayerId); purchase.Card = _cardService.GetCard(request.Selected_CardId); _purchaseService.AddPurchase(purchase); ViewBag.Message = "Success."; return(View(model)); }
private void SavePurchase() { _newTotal = Purchase.Total; Purchase.Total = _oldTotal; if (Purchase.ID == 0) { _purchaseService.AddPurchase(Purchase); } else { _purchaseService.UpdatePurchase(Purchase); } Purchase.Total = _newTotal; }
public IActionResult CreatePurchase(IEnumerable <ProductModel> products) { if (!ModelState.IsValid) { return(BadRequest("You have to order more than 0")); } var userId = _userManager.GetUserId(User); var result = _purchaseService.AddPurchase(products, userId); if (result) { var email = _userService.GetUserEmail(userId); NotifyPurchaseSubmitted(email); return(Ok()); } return(StatusCode(304)); }
private void Save() { if (Purchase.Total <= 0) { Messages.Error("لا يمكن حفظ فاتورة بهذا الاجمالي " + Purchase.Total); return; } if (SelectedSupplier == null) { Messages.Error("يجب اضافة شركة للفاتورة اولا"); return; } Purchase p = new Purchase(); p.ID = Purchase.PurchaseID; p.SupplierID = SelectedSupplier.ID; p.Date = Purchase.Date; p.Number = Purchase.Number; p.Total = Purchase.Total; p.Paid = Purchase.Paid; if (p.ID == 0) { purchaseService.AddPurchase(p); } else { purchaseService.UpdatePurchase(p); } List <PurchaseItem> lstInsert = new List <PurchaseItem>(); List <PurchaseItem> lstUpdate = new List <PurchaseItem>(); foreach (var d in Purchase.Details) { var pi = new PurchaseItem() { ID = d.PurchaseItemID, ItemID = d.ItemID, PurchaseID = p.ID, Price = d.Price, Quantity = d.Quantity }; if (pi.ID == 0) { lstInsert.Add(pi); } else { lstUpdate.Add(pi); } } if (lstInsert.Count > 0) { purchaseService.AddPurchaseItems(lstInsert); } if (lstUpdate.Count > 0) { purchaseService.UpdatePurchaseItems(lstUpdate); } if (lstDeleted.Count > 0) { purchaseService.DeletePurchaseItems(lstDeleted); } completed = true; Purchase.Name = SelectedSupplier.Name; Purchase.SupplierID = SelectedSupplier.ID; if (_edit) { eventAggregator.GetEvent <PurchaseUpdated>().Publish(Purchase); } else { eventAggregator.GetEvent <PurchaseAdded>().Publish(Purchase); } navigationContext.NavigationService.RequestNavigate(RegionNames.PurchasesMain); }
public int AddPurchase([FromBody] PurchaseFullDto purchase) { return(_purchaseService.AddPurchase(purchase)); }
public ActionResult AddPurchase(PurchaseModel model) { var result = _purchaseService.AddPurchase(model); return(BoolResult(result)); }