Beispiel #1
0
        public async Task <IActionResult> LayoutBooking(string zoneId)
        {
            if (!Cookies.CheckFbLogIn(Request))
            {
                return(RedirectToAction("LogIn", "Authentication"));
            }


            byte[] values; string id = "";
            var    cookies = HttpContext.Request.Cookies;

            HttpContext.Session.TryGetValue("ZoneId", out values);
            if (values != null)
            {
                id = Encoding.ASCII.GetString(values);
            }

            zoneId = (zoneId == null?id:zoneId);
            RestApi api = new RestApi("https://localhost:5003/api/concertSeats/Zone?zoneId=" + zoneId);

            api.SetHeader("Authorization", Cookies.GetToken(Request));

            var data = await api.GetAsync("");

            //data.ReasonPhrase
            //data.StatusCode == 401
            var responseBody = await data.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <Result>(responseBody);
            List <ConcertSeatModel> availableSeats = JsonConvert.DeserializeObject <List <ConcertSeatModel> >(result.Data);

            return(View(availableSeats));
        }
Beispiel #2
0
        public async Task <IActionResult> Booking(int totalSeats, string seatIds)
        {
            if (!Cookies.CheckFbLogIn(Request))
            {
                return(RedirectToAction("LogIn", "Authentication"));
            }

            var seats = seatIds;

            string bookedBy = HttpContext.Request.Cookies["fbLogIn"].ToString();

            //set json for Api
            string jsonBooked = @"
            {
                'seatIds':{0},
                'total':{1},    
                'booking':
                    {
                        '$set':
                            {
                                'bookingStatus': 
                                    {  '_id':'bs02','name':'Sold Out', 
                                        'isActive': true,
                                        'bookedDate':'{2}',
                                        'bookedBy':'{3}'
                                    }
                            }
                    }
                    
            }";
            string bookedDate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");

            jsonBooked = jsonBooked.Replace("{0}", seatIds);
            jsonBooked = jsonBooked.Replace("{1}", totalSeats.ToString());
            jsonBooked = jsonBooked.Replace("{2}", bookedDate);
            jsonBooked = jsonBooked.Replace("{3}", bookedBy);


            RestApi api = new RestApi("https://localhost:5003/api/concertSeats/BookingSeats");

            api.SetHeader("Authorization", Cookies.GetToken(Request));

            var data = await api.AddAsync(jsonBooked);

            var responseBody = await data.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject <Result>(responseBody);

            if (result.Status == Puppy.Model.Business.BusinessStatus.Completed)
            {
                return(RedirectToAction("MyTicket", "Customer"));
            }
            else
            {
                byte[] values; string zoneId = "";
                HttpContext.Session.TryGetValue("ZoneId", out values);
                if (values != null)
                {
                    zoneId = Encoding.ASCII.GetString(values);
                }
                return(RedirectToAction("LayoutBooking", "Concert", zoneId));
            }
        }