Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        public IActionResult GetAll()
        {
            var prices = _priceService.GetAll();
            var model  = _mapper.Map <IList <PriceModel> >(prices);

            return(Ok(model));
        }
Exemplo n.º 3
0
        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
            }));
        }
Exemplo n.º 4
0
        public IActionResult GetAll()
        {
            var result = _priceService.GetAll();

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
Exemplo n.º 5
0
 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));
     }
 }
Exemplo n.º 6
0
        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());
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
 public ApiResultModel <List <PRECIO> > GetAll() => GetApiResultModel(() => _priceService.GetAll <PRECIO>());
 public IEnumerable <Price> GetAll()
 => _priceService.GetAll();
Exemplo n.º 10
0
        public IActionResult Get()
        {
            var price = _priceService.GetAll();

            return(Ok(price));
        }