public HttpResponseMessage GetAll(HttpRequestMessage request) { Func <HttpResponseMessage> func = () => { var model = _priceService.GetAll(); var responseData = Mapper.Map <IEnumerable <Price>, IEnumerable <PriceViewModel> >(model); var response = request.CreateResponse(HttpStatusCode.OK, responseData); return(response); }; return(CreateHttpResponse(request, func)); }
public IActionResult GetAll() { var prices = _priceService.GetAll(); var model = _mapper.Map <IList <PriceModel> >(prices); return(Ok(model)); }
public JsonResult Add(int Id, int Quantity = 1) { var cart = (List <ShoppingCartViewModel>)Session[CommonConstants.SessionCart]; var PriceProduct = _priceService.GetById(Id); var PriceProductAll = _priceService.GetAll().ToList(); //var product = _productService.GetById(PriceProduct.ProductID); if (cart == null) { cart = new List <ShoppingCartViewModel>(); } //if (product.Quantity == 0) //{ // return Json(new // { // status = false, // message = "Sản phẩm này hiện đang hết hàng" // }); //} if (cart.Any(x => x.Id == Id)) { foreach (var item in cart) { if (item.Id == Id) { item.Quantity += Quantity; } } } else { ShoppingCartViewModel newItem = new ShoppingCartViewModel(); Product product = _productService.GetById(PriceProduct.ProductID); product.Price = PriceProduct.SalePrice; product.PromotionPrice = PriceProduct.PromotionPrice; newItem.Product = Mapper.Map <Product, ProductViewModel>(PriceProduct.Product); newItem.Id = PriceProduct.ID; newItem.ProductId = PriceProduct.Product.ID; newItem.Quantity = Quantity; newItem.SalePrice = PriceProduct.SalePrice; newItem.PromotionPrice = PriceProduct.PromotionPrice; newItem.SizeId = PriceProduct.SizeID; newItem.ColorId = PriceProduct.ColorID; newItem.ColorName = _colorService.GetById(PriceProduct.ColorID).Name; newItem.SizeName = _sizeService.GetById(PriceProduct.SizeID).Name; cart.Add(newItem); } Session[CommonConstants.SessionCart] = cart; return(Json(new { status = true, data = cart })); }
public IActionResult GetAll() { var result = _priceService.GetAll(); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public IActionResult Get(int id) { try { List <PriceList> priceLists = _priceContext.GetAll(t => t.TariffId == id); return(Ok(priceLists)); } catch (Exception e) { return(StatusCode(StatusCodes.Status500InternalServerError, e.Message)); } }
public async Task <CombinedProduct[]> GetAll() { var productsTask = productService.GetAll(); var pricesTask = priceService.GetAll(); await Task.WhenAll(productsTask, pricesTask); var products = productsTask.Result; var prices = pricesTask.Result; return(products .Select(product => Combine(product, prices.SingleOrDefault(p => p.Code == product.Code))) .ToArray()); }
private Booking CreateBooking(CreateBookingModel model) { // map model to entity var booking = _mapper.Map <Booking>(model); // get current user id string authHeaderValue = Request.Headers["Authorization"]; var tokenClaims = SecurityClaimsHelper.GetClaims(authHeaderValue.Substring("Bearer ".Length).Trim(), _appSettings.Secret); var userId = tokenClaims.Claims.Where(c => c.Type == ClaimTypes.Name).FirstOrDefault().Value; booking.UserId = int.Parse(userId); // get price for the period decimal totalPrice = 0; for (var i = booking.From; i <= booking.To; i = i.AddDays(1)) { var price = _priceService.GetAll(i.Date, i.Date).FirstOrDefault(); totalPrice += price == null ? 0 : price.Value; } booking.TotalPrice = totalPrice; return(booking); }
public ApiResultModel <List <PRECIO> > GetAll() => GetApiResultModel(() => _priceService.GetAll <PRECIO>());
public IEnumerable <Price> GetAll() => _priceService.GetAll();
public IActionResult Get() { var price = _priceService.GetAll(); return(Ok(price)); }