Ejemplo n.º 1
0
        public IActionResult GetForUser()
        {
            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;

            var prices = _bookingService.GetAll(int.Parse(userId));
            var model  = _mapper.Map <IList <BookingModel> >(prices);

            return(Ok(model));
        }
Ejemplo n.º 2
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);
        }