public PaymentInfo Pay(int customerId, Cart cart, string cvv) { using (var dbContextScope = _dbContextScopeFactory.Create()) { var customer = _customerRepository.FindById(customerId); if (customer == null) { //TODO: CustomerNotFoundException throw new Exception(); } customer.Card.CVV = cvv; var paymentInfo = _paymentService.Payment(customer.Card, cart.Cost); cart.Items.ToList().ForEach(x => x.Item = _itemQueryService.GetItem(x.Item.Id)); //TODO: remove hack var order = new Order { Cart = cart, DateTime = DateTime.Now, OrderStatus = paymentInfo.OrderStatus }; customer.Orders.Add(order); _customerRepository.Modify(customer); customer.Card.CVV = null; dbContextScope.SaveChanges(); return(paymentInfo); } }
// GET: Item/Details/5 public ActionResult Details(int?id) { _logger.InfoFormat("View details about item with id [{0}]", id); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Item item = _itemQueryService.GetItem(id.Value); if (item == null) { _logger.InfoFormat("Item with id [{0}] was not found", id); return(HttpNotFound()); } _logger.InfoFormat("Item with id [{0}] was successfully found", id); return(View(item)); }
public ActionResult Details(int?itemId) { _logger.InfoFormat("View details of an item with id [{0}]", itemId); if (itemId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } try { var item = _itemQueryService.GetItem(itemId.Value); _logger.InfoFormat("Item with id [{0}] was successfully found", itemId); return(View(item)); } catch (ArgumentException) { _logger.InfoFormat("Item with id [{0}] details cannot be displayed", itemId); return(HttpNotFound()); } }
public ActionResult AddToCart(FormCollection fc) { int id = Convert.ToInt32(fc["itemId"]); int quantity = 0; try { quantity = Convert.ToInt32(fc["quantity"]); } catch (ArgumentOutOfRangeException) { quantity = 1; } var cart = (Cart)Session["Cart"]; _logger.InfoFormat("Add [{0}] items with id [{1}] to cart. Item count in cart [{2}]. Cart cost [{3}]", quantity, id, Session["Count"], cart != null ? cart.Cost : 0); //int id = Convert.ToInt32(fc["ItemId"]); /*if(id == null) //TODO: error handling * return RedirectToAction("Index"); */ Item item = _itemQueryService.GetItem(id); if (item == null) //TODO: error handling { _logger.InfoFormat("Item with id [{0}] is not found", id); return(RedirectToAction("Index")); } if (cart == null) { cart = new Cart() { Items = new List <CartItem>() }; Session["Cart"] = cart; } if ((cart.Items.FirstOrDefault(i => i.Item.Id == id) != null)) { cart.Items.Where(x => x.Item.Id == id).ToList() .ForEach(y => y.Quantity += quantity); } else { CartItem cartItem = new CartItem() { Cart = (Cart)Session["Cart"], Item = item, Quantity = quantity }; cart.Items.Add(cartItem); } cart.Cost = cart.CountCartPrice(cart.Items); Session["Count"] = _cartService.CountItemsInCart(cart.Items); _logger.InfoFormat("Item with id [{0}] added to cart. Item count in cart [{1}]. Cart cost [{2}]", id, Session["Count"], cart.Cost); return(Json(new { message = item.Name + "(" + quantity + ")" + " was Added to Cart", itemCount = Session["Count"] })); }