コード例 #1
0
        public IHttpActionResult GetBookings(int id)
        {
            Bookings      bookings    = db.Bookings.Find(id);
            BookingModell resBookings = new BookingModell();
            UserModel     tempUser    = new UserModel();
            EventModell   test        = new EventModell();

            if (bookings == null)
            {
                return(NotFound());
            }

            try
            {
                test     = GetEvent(bookings.Event_Id).Result;
                tempUser = GetUser(bookings.User_Id).Result;
            }
            catch (InvalidOperationException e)
            {
            }


            resBookings.Booking_Id           = bookings.Booking_Id;
            resBookings.Event_Id             = test.Event_Id;
            resBookings.Event_Name           = test.Event_Name;
            resBookings.Event_Start_Datetime = test.Event_Start_Datetime;
            resBookings.Event_End_Datetime   = test.Event_End_Datetime;
            resBookings.User_Id = bookings.User_Id;
            if (tempUser != null)
            {
                resBookings.User_Name = tempUser.Firstname + " " + tempUser.Lastname;
            }
            else
            {
                resBookings.User_Name = bookings.User_Id.ToString();
            }
            resBookings.User_Type = bookings.User_Type;



            return(Ok(resBookings));
        }
コード例 #2
0
        private async Task <EventModell> GetEvent(int id) //Hämtar ett event från eventjänsten
        {
            EventModell eventObj = new EventModell();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(baseURLEvent);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage res = client.GetAsync("events/" + id).Result;

                if (res.IsSuccessStatusCode)
                {
                    var response = res.Content.ReadAsStringAsync().Result;
                    eventObj = JsonConvert.DeserializeObject <EventModell>(response);
                    return(eventObj);
                }
            }

            return(eventObj);
        }
コード例 #3
0
        public List <BookingModell> GetBookingFromUser(int uId)
        {
            List <BookingModell> bookingList = new List <BookingModell>();
            EventModell          tempEvent   = new EventModell();
            UserModel            tempUser    = new UserModel();

            var sql = db.Bookings.Where(u => u.User_Id == uId).Select(u => u.Booking_Id).ToArray(); //Hämtar bokningsID utefter en specifik användare
            int eventId;

            for (int i = 0; i < sql.Count(); i++)
            {
                int temp = sql[i];

                string userType = db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.User_Type).FirstOrDefault();

                try
                {
                    tempEvent = GetEvent(db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.Event_Id).FirstOrDefault()).Result; //Hämtar evendata
                    tempUser  = GetUser(uId).Result;                                                                                    //Hämta användar data.
                }
                catch (InvalidOperationException e)
                {
                    log.Error(e);
                    //Lägg in loggning här.
                    for (var t = 0; t < sql.Count(); t++)
                    {
                        temp     = sql[t];
                        userType = db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.User_Type).FirstOrDefault();
                        eventId  = db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.Event_Id).FirstOrDefault();
                        bookingList.Add(new BookingModell
                        {
                            Booking_Id = temp,
                            Event_Id   = eventId,
                            User_Id    = uId,
                            User_Type  = userType
                        });
                    }
                    return(bookingList);
                }
                if (tempUser != null)
                {
                    bookingList.Add(new BookingModell
                    {
                        Booking_Id           = temp,
                        Event_Id             = tempEvent.Event_Id,
                        Event_Name           = tempEvent.Event_Name,
                        Event_Start_Datetime = tempEvent.Event_Start_Datetime,
                        Event_End_Datetime   = tempEvent.Event_End_Datetime,
                        User_Id   = uId,
                        User_Name = tempUser.Firstname + " " + tempUser.Lastname,
                        User_Type = userType
                    });
                }
                else
                {
                    bookingList.Add(new BookingModell
                    {
                        Booking_Id           = temp,
                        Event_Id             = tempEvent.Event_Id,
                        Event_Name           = tempEvent.Event_Name,
                        Event_Start_Datetime = tempEvent.Event_Start_Datetime,
                        Event_End_Datetime   = tempEvent.Event_End_Datetime,
                        User_Id   = uId,
                        User_Name = uId.ToString(),
                        User_Type = userType
                    });
                }
            }


            return(bookingList);
        }
コード例 #4
0
        public List <BookingModell> GetBookings()
        {
            List <BookingModell> bookingList = new List <BookingModell>();
            EventModell          tempEvent   = new EventModell();
            UserModel            tempUser    = new UserModel();

            var    sql = db.Bookings.Select(s => s.Booking_Id).ToArray(); //Hämtar alla ID från alla rader.
            string userType;
            int    eventId;

            for (var i = 0; i < sql.Count(); i++) //Kör forloopen så många gånger som rader det finns i databasen
            {
                var temp   = sql[i];
                int userId = db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.User_Id).FirstOrDefault(); //Hämtar användar ID för första raden.

                try
                {
                    tempEvent = GetEvent(db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.Event_Id).FirstOrDefault()).Result; //Hämtar information från event tjänsten utefter eventID på raden.
                    tempUser  = GetUser(userId).Result;                                                                                 //Hämtar användar ID från logintjänsten utefter användarID från databasen
                }
                catch (InvalidOperationException e)                                                                                     //Ifall tjänsterna inte funkar så hämtas enbart ID från databasen och returneras
                {
                    log.Error(e);                                                                                                       //loggar exception
                    for (var t = 0; t < sql.Count(); t++)
                    {
                        temp     = sql[t];
                        userType = db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.User_Type).FirstOrDefault();
                        userId   = db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.User_Id).FirstOrDefault();
                        eventId  = db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.Event_Id).FirstOrDefault();
                        bookingList.Add(new BookingModell
                        {
                            Booking_Id = temp,
                            Event_Id   = eventId,
                            User_Id    = userId,
                            User_Type  = userType
                        });
                    }
                    return(bookingList);
                }

                userType = db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.User_Type).FirstOrDefault();

                if (tempUser != null)
                {
                    bookingList.Add(new BookingModell //Sparar ner alla värden i en lista
                    {
                        Booking_Id           = temp,
                        Event_Id             = tempEvent.Event_Id,
                        Event_Name           = tempEvent.Event_Name,
                        Event_Start_Datetime = tempEvent.Event_Start_Datetime,
                        Event_End_Datetime   = tempEvent.Event_End_Datetime,
                        User_Id   = userId,
                        User_Name = tempUser.Firstname + " " + tempUser.Lastname,
                        User_Type = userType
                    });
                }
                else
                {
                    bookingList.Add(new BookingModell //Temporär felhantering då användaren inte finns i användardatabasen men i våran.
                    {
                        Booking_Id           = temp,
                        Event_Id             = tempEvent.Event_Id,
                        Event_Name           = tempEvent.Event_Name,
                        Event_Start_Datetime = tempEvent.Event_Start_Datetime,
                        Event_End_Datetime   = tempEvent.Event_End_Datetime,
                        User_Id   = userId,
                        User_Name = userId.ToString(),
                        User_Type = userType
                    });
                }
            }
            return(bookingList);
        }
コード例 #5
0
        public List <BookingModell> GetVolounteerOnEvent(int eId)
        {
            List <BookingModell> bookingList = new List <BookingModell>();
            EventModell          tempEvent   = new EventModell();
            UserModel            tempUser    = new UserModel();

            var sql = db.Bookings.Where(b => b.User_Type == "Volontär").Where(s => s.Event_Id == eId).Select(s => s.Booking_Id).ToArray(); //Hämtar ID från alla rader som finns för alla volontärer på ett specifikt event


            for (var i = 0; i < sql.Count(); i++)
            {
                var    temp     = sql[i];
                int    user     = db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.User_Id).FirstOrDefault();
                string userType = db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.User_Type).FirstOrDefault();

                try
                {
                    tempEvent = GetEvent(db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.Event_Id).FirstOrDefault()).Result; //Hämtar eventinfo
                    tempUser  = GetUser(user).Result;                                                                                   //Hämtar användar info
                }
                catch (InvalidOperationException e)
                {
                    log.Error(e);
                    //Lägg in loggning här.
                    for (var t = 0; t < sql.Count(); t++)
                    {
                        temp     = sql[t];
                        userType = db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.User_Type).FirstOrDefault();
                        user     = db.Bookings.Where(s => s.Booking_Id == temp).Select(s => s.User_Id).FirstOrDefault();
                        bookingList.Add(new BookingModell
                        {
                            Booking_Id = temp,
                            Event_Id   = eId,
                            User_Id    = user,
                            User_Type  = userType
                        });
                    }
                    return(bookingList);
                }
                if (tempUser != null)
                {
                    bookingList.Add(new BookingModell
                    {
                        Booking_Id           = temp,
                        Event_Id             = tempEvent.Event_Id,
                        Event_Name           = tempEvent.Event_Name,
                        Event_Start_Datetime = tempEvent.Event_Start_Datetime,
                        Event_End_Datetime   = tempEvent.Event_End_Datetime,
                        User_Id   = user,
                        User_Name = tempUser.Firstname + " " + tempUser.Lastname,
                        User_Type = userType
                    });
                }
                else
                {
                    bookingList.Add(new BookingModell
                    {
                        Booking_Id           = temp,
                        Event_Id             = tempEvent.Event_Id,
                        Event_Name           = tempEvent.Event_Name,
                        Event_Start_Datetime = tempEvent.Event_Start_Datetime,
                        Event_End_Datetime   = tempEvent.Event_End_Datetime,
                        User_Id   = user,
                        User_Name = user.ToString(),
                        User_Type = userType
                    });
                }
            }

            return(bookingList);
        }