Exemplo n.º 1
0
        public IActionResult Get(string userLogin)
        {
            try
            {
                if (!Request.Headers.ContainsKey("access_token"))
                {
                    return(Unauthorized());
                }

                string token       = Request.Headers["access_token"];
                var    authManager = new AuthorizationManager();
                if (!authManager.CheckTokenBelonging(token, userLogin))
                {
                    return(Json(new { error = "Invalid token", error_description = "Given token doesn't belong to this user" }));
                }
                var tokenStatus = authManager.CheckToken(token);
                if (tokenStatus == TokenStatusesEnum.Invalid)
                {
                    return(Json(new { error = "Invalid token", error_description = "Given token is invalid" }));
                }
                else if (tokenStatus == TokenStatusesEnum.Expired)
                {
                    return(Json(new { error = "Expired token", error_description = "Given token is expired. Please refresh it." }));
                }

                var bookings    = new BookingManager().GetUserBookings(userLogin);
                var billManager = new BillingManager();
                foreach (var booking in bookings)
                {
                    booking.Bill = billManager.GetBill(booking.Id);
                }

                return(Json(bookings));
            }
            catch (Exception e)
            {
                return(Json(new { error = "Internal server error", error_description = JsonConvert.SerializeObject(e, Formatting.Indented) }));
            }
        }