Esempio n. 1
0
        public IHttpActionResult PutFacilitiesBooked(int id, FacilitiesBooked facilitiesBooked)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != facilitiesBooked.Id)
            {
                return BadRequest();
            }

            db.Entry(facilitiesBooked).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FacilitiesBookedExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
Esempio n. 2
0
        public async Task AddFacilitiesBooked(FacilitiesBooked newFacilitiesBooked)
        {
            try
            {
                HttpClient client = new HttpClient();

                // Using jsonconvert and creates content
                string jsonString = JsonConvert.SerializeObject(newFacilitiesBooked); // Lägg in ny objekt
                var    content    = new StringContent(jsonString, Encoding.UTF8, "application/json");

                // URL vart datan ska skickas
                string URL = organiserBaseURL + facilitiesBookedURL;

                // Connecting webapi
                var response = await client.PostAsync(URL, content);

                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();
                }
            }
            catch (Exception e)
            {
                Logger.Error(e, "Error Level");
            }
        }
Esempio n. 3
0
        public async Task <ActionResult> CreateEvent(Events newEvent, int Category_Id, int FacilityID)
        {
            FacilitiesBooked facilitiesBooked = new FacilitiesBooked();

            try
            {
                newEvent.Event_Category             = new EventCategory();
                newEvent.Event_Category.Category_Id = Category_Id;
                newEvent.Event_Create_Datetime      = DateTime.Now;

                // Nytt:
                newEvent.Event_Facility = new EventFacility()
                {
                    Id = FacilityID
                };

                newEvent.Event_Organizer = new EventOrganizer()
                {
                    Id = int.Parse(Session["userID"].ToString())
                };


                // In case value is null. Value cannot be null
                if (newEvent.Event_Seeking_Volunteers != true)
                {
                    newEvent.Event_Seeking_Volunteers = false;
                }

                if (newEvent.Event_Active != true)
                {
                    newEvent.Event_Active = false;
                }

                // Booked facility
                facilitiesBooked.DateStart    = newEvent.Event_Start_Datetime;
                facilitiesBooked.DateEnd      = newEvent.Event_End_Datetime;
                facilitiesBooked.Fk_Facility  = newEvent.Event_Facility.Id;
                facilitiesBooked.Fk_Organizer = newEvent.Event_Organizer.Id;

                // Add objects in respective database
                await obj.AddFacilitiesBooked(facilitiesBooked);

                await obj.AddEvent(newEvent);


                // Om allt går bra
                return(RedirectToAction("Index", "Organizer"));
            }
            catch (Exception e)
            {
                Logger.Error(e, "Error Level");
                Logger.Fatal(e, "Fatal Level");

                TempData["tempErrorMessage"] = e.Message.ToString();
                return(RedirectToAction("Error", "Help"));
            }
        }
Esempio n. 4
0
        public IHttpActionResult GetFacilitiesBooked(int id)
        {
            FacilitiesBooked facilitiesBooked = db.FacilitiesBooked.Find(id);
            if (facilitiesBooked == null)
            {
                return NotFound();
            }

            return Ok(facilitiesBooked);
        }
Esempio n. 5
0
        public IHttpActionResult PostFacilitiesBooked(FacilitiesBooked facilitiesBooked)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.FacilitiesBooked.Add(facilitiesBooked);
            db.SaveChanges();

            return CreatedAtRoute("DefaultApi", new { id = facilitiesBooked.Id }, facilitiesBooked);
        }
Esempio n. 6
0
        public IHttpActionResult DeleteFacilitiesBooked(int id)
        {
            FacilitiesBooked facilitiesBooked = db.FacilitiesBooked.Find(id);
            if (facilitiesBooked == null)
            {
                return NotFound();
            }

            db.FacilitiesBooked.Remove(facilitiesBooked);
            db.SaveChanges();

            return Ok(facilitiesBooked);
        }
Esempio n. 7
0
        public async Task UpdateFacilitiesBooked(FacilitiesBooked updatedFacilitiesBooked)
        {
            HttpClient client = new HttpClient();

            // URL for customer id selected by user
            string URL = organiserBaseURL + facilitiesBookedURL + "/" + updatedFacilitiesBooked.Id.ToString();

            var response = await client.GetAsync(new Uri(URL));

            if (response.IsSuccessStatusCode)
            {
                // Json and webapi
                string jsonstring    = JsonConvert.SerializeObject(updatedFacilitiesBooked);
                var    content       = new StringContent(jsonstring, Encoding.UTF8, "Application/json");
                var    responsupdate = await client.PutAsync(URL, content);
            }
        }
Esempio n. 8
0
        public async Task <FacilitiesBooked> GetFacilitiesBookedByID(int id)
        {
            FacilitiesBooked facilitiesBooked = new FacilitiesBooked();
            HttpClient       client           = new HttpClient();

            string URL = organiserBaseURL + facilitiesBookedURL + "/" + id.ToString();

            var response = await client.GetAsync(new Uri(URL));

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                facilitiesBooked = JsonConvert.DeserializeObject <FacilitiesBooked>(content);
            }
            return(facilitiesBooked);
        }