public List <ProductDTO> MapProductsToProductsDTO(List <Product> products) { List <ProductDTO> productsDto = new List <ProductDTO>(); foreach (var product in products) { ProductDTO productDto = new ProductDTO() { Id = product.Id, Name = product.Name, Description = product.Description, ImagePath = product.ImagePath }; foreach (var price in product.Prices) { ProductPriceDTO productPriceDto = new ProductPriceDTO() { Date = price.Date, Price = price.Price }; productDto.Prices.Add(productPriceDto); } productsDto.Add(productDto); } return(productsDto); }
public List <ProductDTO> Scrap(string url) { HtmlWeb webDoc = new HtmlWeb(); HtmlDocument doc = webDoc.Load(url); var allNodes = doc.DocumentNode.SelectNodes("//a[contains(@class,'product-thumb')]"); List <ProductDTO> comps = new List <ProductDTO>(); foreach (var mainNode in allNodes) { HtmlNode titleNode = mainNode.SelectSingleNode("*[contains(@class,'product-thumb__inner')]/*[contains(@class,'product-thumb__info')]/*[contains(@class,'product-thumb__name')]"); HtmlNode descNode = mainNode.SelectSingleNode("*[contains(@class,'product-thumb__inner')]/*[contains(@class,'product-thumb__description')]"); HtmlNode imgNode = mainNode.SelectSingleNode("*[contains(@class,'product-thumb__inner')]/*[contains(@class,'product-thumb__image-wrapper')]/img"); HtmlNode priceNode = mainNode.SelectSingleNode("*[contains(@class,'product-thumb__inner')]/*[contains(@class,'product-thumb__prices')]/*[contains(@class,'product-thumb__price')]"); ProductDTO comp = new ProductDTO(); //comp.Link = titleNode.Attributes["href"].Value; comp.Name = titleNode.InnerText; comp.ImagePath = imgNode.Attributes["src"].Value; comp.Description = descNode.InnerText; ProductPriceDTO price = new ProductPriceDTO() { Date = DateTime.Now, Price = priceNode.InnerText }; comp.Prices.Add(price); comps.Add(comp); } return(comps); }
public IHttpActionResult AddProductPrice(ProductPriceDTO productPriceDto) { if (!ModelState.IsValid) { return(BadRequest()); } _productPriceLogic.Create(productPriceDto); return(Created(new Uri(Request.RequestUri + "/" + productPriceDto.Id), productPriceDto)); }
public RedirectToRouteResult RemoveFromCart(int productPriceId, string returnUrl) { ProductPriceDTO productPriceDTO = productPriceService.Get(productPriceId); if (productPriceDTO != null) { GetCart().RemoveLine(productPriceDTO); } return(RedirectToAction("Index", new { returnUrl })); }
public ActionResult AddToCart(int id) { ProductPriceDTO productPriceDTO = productPriceService.Get(id); if (productPriceDTO != null) { GetCart().AddItem(productPriceDTO, 1); } // return RedirectToAction("Index", new { returnUrl }); return(Json("OK")); }
public ActionResult Delete(int id) { try { ProductPriceDTO productPrice = productPriceService.Get(id); productPriceService.Delete(productPrice); return(Json("OK")); } catch { return(Json("Error")); } }
public async Task <IActionResult> Index(BookViewModel bookViewModel) { if (ModelState.IsValid) { string paxId = HttpContext.Session.GetString(SessionDataKeys.PaxId); //Calculate Product Price ProductPriceDTO productPrice = await getProductPricing(bookViewModel.ProductId, bookViewModel.CheckInDate, bookViewModel.CheckInTime); bookViewModel.CalculateFinalPrice(productPrice); //Create Booking CreateBookingCommand createBookingCommand = new CreateBookingCommand { Name = bookViewModel.ProductName }; CreateBookingCommandItem bookingItem = new CreateBookingCommandItem() { ProductId = bookViewModel.ProductId, DateCheckIn = bookViewModel.CheckInDate.ToJsonDateTime(bookViewModel.CheckInTime), }; bookingItem.PaxId.Add(paxId); createBookingCommand.BookingProducts.Add(bookingItem); BookingProductDTO bookingProductDTO = await _heroService.BookingApi.CreateBookingAsync(createBookingCommand); //Validate Booking BookingValidationResultDTO bookResult = await _heroService.BookingApi.ValidateBookingAsync(bookingProductDTO.Id); if (bookResult.IsValid) { //Create the payment CreatePaymentCommand createPaymentCommand = new CreatePaymentCommand() { Amount = bookViewModel.FinalPrice, BookingId = bookingProductDTO.Id, IsFinal = true, Method = PaymentMethod.Cash, PaxId = paxId }; await _heroService.PaymentApi.CreatePaymentAsync(createPaymentCommand); return(RedirectToAction("Index", "Voucher", new { bookingId = bookingProductDTO.Id, paxId })); } else { this.ModelState.AddModelError("BookValidation", "Book validation failed please retry"); } } return(View(bookViewModel)); }
public IHttpActionResult UpdateProductPrice(ProductPriceDTO productPriceDto) { if (!ModelState.IsValid) { return(BadRequest()); } var productPriceInDb = _productPriceLogic.FindByID(productPriceDto.Id); if (productPriceInDb == null) { return(NotFound()); } return(Ok(_productPriceLogic.Update(productPriceDto))); }
public async Task <IActionResult> CheckPrice(CheckPriceViewModel checkPriceViewModel) { string sessionBook = HttpContext.Session.GetString(SessionDataKeys.MyBook); BookViewModel bookViewModel = JsonConvert.DeserializeObject <BookViewModel>(sessionBook); ProductPriceDTO productPriceDTO = await getProductPricing(bookViewModel.ProductId, checkPriceViewModel.CheckInDate, checkPriceViewModel.CheckInTime); bookViewModel.CalculateFinalPrice(productPriceDTO); var priceSnapShot = new { DiscountAmount = $"{bookViewModel.Currency} {bookViewModel.DiscountAmount}", FinalPrice = $"{bookViewModel.Currency} {bookViewModel.FinalPrice}", OriginalPrice = $"{bookViewModel.Currency} {bookViewModel.OriginalPrice}", }; return(Json(priceSnapShot)); }
public ActionResult Edit(ProductPriceDTO productPrice) { if (ModelState.IsValid) { if (productPrice.SubCategoryId == 0) { productPrice.SubCategoryId = null; } if (productPrice.TasteCategoryId == 0) { productPrice.TasteCategoryId = null; } productPriceService.AddOrUpdate(productPrice); return(RedirectToAction("IndexHtmlAction")); } return(View("Edit")); }
public void AddItem(ProductPriceDTO productPriceDTO, int quantity) { CartLine line = lineCollection.Where(g => g.ProductPricecart.ProductPriceId == productPriceDTO.ProductPriceId).FirstOrDefault(); if (line == null) { lineCollection.Add(new CartLine { ProductPricecart = productPriceDTO, Quantity = quantity }); } else { line.Quantity += quantity; } }
public void GetProductPrice(int cruiseId) { var productPrices = Module.IvGetProductPrices(cruiseId); var list = new List <ProductPriceDTO>(); foreach (IvProductPrice r in productPrices) { var productPriceDto = new ProductPriceDTO(); productPriceDto.Price = r.Price; productPriceDto.ProductId = r.Product.Id; productPriceDto.UnitId = r.Unit.Id; productPriceDto.StorageId = r.Storage.Id; list.Add(productPriceDto); } HttpContext.Current.Response.ContentType = "application/json"; HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.Write(JsonConvert.SerializeObject(list)); }
public ProductDTO Create(ProductDTO c) { try { var product = MapDTO.Map <Product, ProductDTO>(c); ProductPriceDTO price = _prdPriceLogic.GetAll().Last(); product.PriceId = price.Id; _uow.ProductRepo.Add(product); _uow.Save(); c.Id = product.Id; return(c); } catch (Exception e) { log.Error("kon geen product toevoegen", e); throw new Exception(e.Message); } }
public ProductDTO MapProductToProductDTO(Product product) { ProductDTO productDto = new ProductDTO() { Id = product.Id, Name = product.Name, Description = product.Description, ImagePath = product.ImagePath }; foreach (var price in product.Prices) { ProductPriceDTO productPriceDto = new ProductPriceDTO() { Date = price.Date, Price = price.Price }; productDto.Prices.Add(productPriceDto); } return(productDto); }
public void RemoveLine(ProductPriceDTO productPriceDTO) { lineCollection.RemoveAll(l => l.ProductPricecart.ProductPriceId == productPriceDTO.ProductPriceId); }