public async Task PurchaseMovie(PurchaseMovieRequestModel purchaseMovieRequest) { if (_currentUserService.UserId != purchaseMovieRequest.UserId) { throw new HttpException(HttpStatusCode.Unauthorized, "You are not Authorized to purchase"); } purchaseMovieRequest.UserId = _currentUserService.UserId; // See if Movie is already purchased. if (await IsMoviePurchased(purchaseMovieRequest)) { throw new ConflictException("Movie already Purchased"); } // Get Movie Price from Movie Table var movie = await _movieService.GetMovieDetailsById(purchaseMovieRequest.MovieId); var purchase = new Purchase { UserId = _currentUserService.UserId, PurchaseNumber = (Guid)purchaseMovieRequest.PurchaseNumber, TotalPrice = (decimal)movie.Price, PurchaseDateTime = (DateTime)purchaseMovieRequest.PurchaseDateTime, MovieId = purchaseMovieRequest.MovieId }; await _purchaseRepository.Add(purchase); }
public async Task <IActionResult> Register([FromBody] PurchaseDTO purchase) { try { _logger.LogInformation("register purchase of currency"); Currencies currencyVal = _getCurrency(purchase.Currency); var quotation = await _quotationRepository.GetQuotation(currencyVal); var value = await UpdateAmount(purchase.Amount, quotation, currencyVal); if (!CheckAmountLimits(value, currencyVal, purchase.UserId)) { return(BadRequest(new InternalServerError("El limite de compra se ha excedido"))); } var purchaseEntity = new Purchase() { Amount = purchase.Amount, Value = value, UserId = purchase.UserId, Currency = purchase.Currency }; await _purchaseRepository.Add(purchaseEntity); return(Ok(purchaseEntity)); } catch (Exception e) { _logger.LogError("error: " + e.Message); return(StatusCode(500, "Internal server error")); } }
public ActionResult Add([FromBody] PurchaseDTO purchaseDTO) { var purchase = purchaseDTO.getPurchase(GetUserId()); _purchaseRepository.Add(purchase); return(Created("", purchase)); }
public bool AddToCart(ProductViewModel item) { Products product = _productRepository.Get(item.Id); bool canBuy = (product != null && product.Quantity > 0 && product.Quantity >= item.QuantityToBuy); if (canBuy) { try { var purchase = new Purchase { CustomerID = item.BuyerId, Finished = false, ProductID = item.Id, Quantity = item.QuantityToBuy }; _purchaseRespository.Add(purchase); } catch (Exception) { } } return(canBuy); }
public async Task PurchaseMovie(PurchaseRequestModel model) { if (_currentUserService.UserId != model.UserId) { throw new HttpException(HttpStatusCode.Unauthorized, "You are not Authorized to purchase"); } model.UserId = _currentUserService.UserId; // See if Movie is already purchased. if (await IsMoviePurchased(model)) { throw new ConflictException("Movie already Purchased"); } // Get Movie Price from Movie Table var movie = await _movieService.GetMovieDetailsById(model.MovieId); model.TotalPrice = movie.Price; //var purchase = _mapper.Map<Purchase>(purchaseRequest); var purchase = new Purchase { UserId = model.UserId, PurchaseNumber = model.PurchaseNumber, TotalPrice = model.TotalPrice, PurchaseDateTime = model.PurchaseDateTime, MovieId = model.MovieId, }; await _purchaseRepository.Add(purchase); }
public void Sell(Guid tutorId, Guid productId, string customer, string phoneNumber) { var tutor = _tutorMgr.GetById(tutorId); var product = _productMgr.Get(productId); Purchase purchase; Member member = null; if (product is MemberProduct) { member = _memberMgr.Get(phoneNumber); if (member == null) { throw new MemberNotExistException(); } purchase = tutor.Sell((MemberProduct)product, member); _memberMgr.Modify(member); foreach (var balance in member.Balances) { _balanceMgr.Modify(balance); } } else { purchase = tutor.Sell((OneTimeExperience)product); } purchase.GenerateNewIdentity(); _purchaseRepository.Add(purchase); _purchaseRepository.UnitOfWork.Commit(); }
public IActionResult Create([FromBody] Purchase value) { if (value == null) { return(BadRequest()); } value.DatePurchase = DateTime.Now; _repository.Add(value); return(new NoContentResult()); }
public override async Task <ActionResult> HandleAsync([FromBody] CreatePurchaseRequest request, CancellationToken cancellationToken = default) { var Purchase = new Purchase { Id = request.Id, VendorId = request.VendorId, Date = request.Date, ReferenceNumber = request.ReferenceNumber }; await _repo.Add(Purchase); await _repo.Save(); return(Ok(Purchase)); }
public async Task <IActionResult> Create([Bind("PurchaseId,ClientId,SellerId,YachtId,PurchaseDate")] Purchase purchase) { if (ModelState.IsValid) { _purchaseRepository.Add(purchase); await _unitOfWork.SaveChanges(); return(RedirectToAction(nameof(Index))); } ViewData["ClientId"] = new SelectList(await _clientRepository.GetAll(), "ClientId", "FullName", null); ViewData["SellerId"] = new SelectList(await _sellerRepository.GetAll(), "SellerId", "FullName", null); ViewData["YachtId"] = new SelectList(await _yachtRepository.GetAll(), "YachtId", "FullView", null); return(View(purchase)); }
public ActionResult PostSelectedProducts(List <ProductDetail> model) { Purchase p = new Purchase(); foreach (var m in model) { if (m.Checked) { Guid obj = Guid.NewGuid(); p.Id = obj.ToString(); p.ProductId = m.Id; p.UserId = User.Claims.First(c => c.Type == "UserID").Value; _purchaserepository.Add(p); } } return(Ok()); }
public async Task <IActionResult> CreatePurchase([FromBody] PurchaseSaveResource purchaseResource) { if (!ModelState.IsValid) { return(BadRequest()); } var purchase = mapper.Map <PurchaseSaveResource, Purchase>(purchaseResource); purchase.User = userManager.GetUserAsync(HttpContext.User).Result; purchase.TimeIssued = DateTime.Now; repository.Add(purchase); await unitOfWork.CompleteAsync(); purchase = await repository.GetPurchase(purchase.ID); var result = mapper.Map <Purchase, PurchaseSaveResource>(purchase); return(Created(nameof(GetPurchase), result)); }
public void PurchaseProductById(int id) { var userId = Convert.ToInt32(_ctxAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); Product productEntity = _productRepository.Get(id); if (productEntity == null) { throw new Exception("Invalid Product"); } Purchase purchaseEntity = new Purchase() { Price = productEntity.Price, ProductId = productEntity.Id, UserId = userId }; _purchaseRepository.Add(purchaseEntity); db.SaveChanges(); }
public ActionResult Checkout(CheckoutViewModel model) { if (!ModelState.IsValid) { return(View(model)); } using (ITransaction transaction = _session.BeginTransaction()) { var cart = _cartRepository.GetCartByCustomerId(model.CustomerId); var address = new DeliveryAddress(model.City, model.Address); var phone = new Phone(model.Phone); var purchase = cart.Checkout(address, phone); _purchaseRepository.Add(purchase); transaction.Commit(); } return(RedirectToAction("Index")); }
public void Add(string itemId) { Console.WriteLine(@"In purchaseService with " + itemId); purchaseRepository.Add(itemId); }
public void AddtoCart(long idUser, long idProduct, int Quantity) { long check = 0; IEnumerable <long> distinctedPurchaseId = (from p in GetAll() where p.UserId == idUser select p.PurchaseId).Distinct(); foreach (int i in distinctedPurchaseId) { //Purchase p = UOW.GetRepository<Purchase>().GetById(i); Purchase p = _purchaseRespository.Find(i); if (p.Status.Equals("Cart")) { check = p.PurchaseId; } } if (check == 0) { Purchase pp = new Purchase { DatePurchase = DateTime.Now, Total = (_productRespository.Find(idProduct).Price) * Quantity, Status = "Cart" }; _purchaseRespository.Add(pp); // UOW.Commit(); long idNewPurchase = _purchaseRespository.GetAll().Select(x => x.PurchaseId).Max(); Order o = new Order { PurchaseId = idNewPurchase, ProductId = idProduct, UserId = idUser, Quantity = Quantity }; Add(o); // UOW.GetRepository<Order>().Add(o); // UOW.Commit(); } else { long checkProduct = 0; Purchase pp = _purchaseRespository.Find(check); pp.Total = pp.Total + (_productRespository.Find(idProduct).Price) * Quantity; _purchaseRespository.Update(pp); // UOW.Commit(); long idNewPurchase = pp.PurchaseId; Order o = new Order { PurchaseId = idNewPurchase, ProductId = idProduct, UserId = idUser, Quantity = Quantity }; foreach (Order order in GetAll().Where(x => x.PurchaseId == idNewPurchase)) { if (order.ProductId == idProduct) { order.Quantity = Quantity; Update(order); checkProduct = 1; // UOW.Commit(); } } if (checkProduct != 1) { Add(o); // UOW.Commit(); } } }
public Purchase Add(Purchase purchase) { return(repository.Add(purchase)); }
public void CreatePurchase(Purchase purchase) { _purchase.Add(purchase); _purchase.Commit(); }
public Purchase Add(Purchase purchase) { _purchaseRepository.Add(purchase); return(purchase); }