public async Task <ActionResult> Index2()
        {
            var test = Request.Form.Files;

            //foreach (var upload in Request.Form.Files)
            //{
            if (test[0].FileName != "")
            {
                // read file to stream
                Stream hold  = test[0].OpenReadStream();
                byte[] array = new byte[hold.Length];
                hold.Seek(0, SeekOrigin.Begin);
                hold.Read(array, 0, array.Length);
                EventIn temp = new EventIn()
                {
                    VideoURL    = null,
                    Name        = "Test",
                    Location    = "York",
                    Date        = "29/10/2020",
                    TimeStart   = "09:00",
                    TimeEnd     = "18:00",
                    Description = "A fun day out",
                    EventFile   = array
                };
                await CreateEventAsync(temp);

                hold.Close();
            }
            //}
            return(View("Upload"));
        }
Esempio n. 2
0
        public async Task <ActionResult> EditEvent(Download download)
        {
            try
            {
                var     url    = "https://localhost:44389/api/1.0/event/" + download.Id;
                EventIn event1 = await GetEventAsync(url.ToString());

                HttpContext.Session.SetString("_VideoURL", "Null");
                HttpContext.Session.SetString("_EventName", event1.Name);
                HttpContext.Session.SetString("_Date", event1.Date);
                HttpContext.Session.SetString("_Location", event1.Location);
                HttpContext.Session.SetString("_TimeStart", event1.TimeStart);
                HttpContext.Session.SetString("_TimeEnd", event1.TimeEnd);
                HttpContext.Session.SetString("_Description", "Null");
                HttpContext.Session.SetString("_EventID", event1.Id);
                return(View("EventUpdate"));
            }
            catch (Exception e)
            {
                string message    = e.Message;
                string stackTrace = e.StackTrace;
                HttpContext.Session.SetString("_Error", "true");
                HttpContext.Session.SetString("_ErrorMessage", message);
                HttpContext.Session.SetString("_ErrorTrace", stackTrace);
                return(View("Error"));
            }
        }
        public async Task <ActionResult> EventUpdater(EventIn events)
        {//This must be an async task
            try
            {
                List <EventReg> eventRegs = await GetEventRegsAsync("https://localhost:44389/api/1.0/eventReg");

                ViewData["eventRegs"] = eventRegs;
                EventIn event1 = await GetEventAsync("https://localhost:44389/api/1.0/event/" + HttpContext.Session.GetString("_EventID"));

                EventIn temp = new EventIn()
                {
                    Name        = events.Name,
                    Location    = events.Location,
                    Date        = events.Date,
                    TimeStart   = events.TimeStart,
                    TimeEnd     = events.TimeEnd,
                    Description = events.Description,
                    VideoURL    = events.VideoURL,
                    EventFile   = event1.EventFile,
                    Id          = event1.Id
                };
                var url = await UpdateEventAsync(temp);

                return(View("Events"));
            }
            catch (Exception e)
            {
                string message    = e.Message;
                string stackTrace = e.StackTrace;
                HttpContext.Session.SetString("_Error", "true");
                HttpContext.Session.SetString("_ErrorMessage", message);
                HttpContext.Session.SetString("_ErrorTrace", stackTrace);
                return(View("Error"));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Handels communicating with the API to get a specific Event
        /// </summary>
        /// <param name="path">
        /// The location of the boat that should be retrieved.
        /// </param>
        /// <returns>
        /// Returns the Event that was retrieved from the API.
        /// </returns>
        static async Task <EventIn> GetEventAsync(string path)
        {
            EventIn             eventIn  = null;
            HttpResponseMessage response = await client.GetAsync(path);

            if (response.IsSuccessStatusCode)
            {
                eventIn = await response.Content.ReadAsAsync <EventIn>();
            }
            return(eventIn);
        }
Esempio n. 5
0
        /// <summary>
        /// Handels communicating with the API to create an Event.
        /// </summary>
        /// <param name="eventIn">
        /// An object containing the information to be passed to the API.
        /// </param>
        /// <returns>
        /// Returns the location in the API of the newly created Event.
        /// </returns>
        static async Task <Uri> CreateEventAsync(EventIn eventIn)
        {
            HttpResponseMessage response = await client.PostAsJsonAsync(
                "https://localhost:44389/api/1.0/event", eventIn);

            response.EnsureSuccessStatusCode();
            var tempURL = response.Headers.Location;

            Console.WriteLine(tempURL);
            return(response.Headers.Location);
        }
Esempio n. 6
0
        /// <summary>
        /// Handels communicating with the API to update the information of
        /// a specific event
        /// </summary>
        /// <param name="eventIn">
        /// An object containing the information to be passed to the API
        /// </param>
        /// <returns>
        /// Will return the status code of the APIs response, should be 420 No Content
        /// </returns>
        static async Task <HttpStatusCode> UpdateEventAsync(EventIn eventIn)
        {
            HttpResponseMessage response = await client.PutAsJsonAsync(
                $"https://localhost:44389/api/1.0/event/{ eventIn.Id}", eventIn);

            response.EnsureSuccessStatusCode();

            // Deserialize the updated product from the response body.
            //eventIn = await response.Content.ReadAsAsync<EventIn>();
            //return eventIn;
            return(response.StatusCode);
        }
Esempio n. 7
0
        /// <summary>
        /// This handels the user equest to download a flyer containing
        /// information about an event
        /// </summary>
        /// <param name="download">
        /// An object that contains the event id that will be used to
        /// locate the correct flyer on the API
        /// </param>
        /// <returns>
        /// Returns the file to the user as a download.
        /// </returns>
        public async Task <FileResult> Download(Download download)
        {
            EventIn tempEvent = await GetEventAsync("https://localhost:44389/api/1.0/event/" + download.Id);

            using (var stream = new MemoryStream())
            {
                stream.Write(tempEvent.EventFile, 0, tempEvent.EventFile.Length);
                stream.Seek(0, SeekOrigin.Begin);
                string filename = tempEvent.Name + tempEvent.Date + ".pdf";
                return(File(stream.GetBuffer(), "application/pdf", filename));
            }
        }
        public async Task <ActionResult> Upload()
        {
            try
            {
                List <EventReg> eventRegs = await GetEventRegsAsync("https://localhost:44389/api/1.0/eventReg");

                ViewData["eventRegs"] = eventRegs;
                //var test = Request.Form.Files;
                foreach (var upload in Request.Form.Files)
                {
                    //if (test[0].FileName != "")
                    //{

                    // read file to stream
                    Stream hold  = upload.OpenReadStream();
                    byte[] array = new byte[hold.Length];
                    hold.Seek(0, SeekOrigin.Begin);
                    hold.Read(array, 0, array.Length);
                    EventIn temp = new EventIn()
                    {
                        VideoURL    = HttpContext.Session.GetString("_VideoURL"),
                        Name        = HttpContext.Session.GetString("_EventName"),
                        Location    = HttpContext.Session.GetString("_Location"),
                        Date        = HttpContext.Session.GetString("_Date"),
                        TimeStart   = HttpContext.Session.GetString("_TimeStart"),
                        TimeEnd     = HttpContext.Session.GetString("_TimeEnd"),
                        Description = HttpContext.Session.GetString("_Description"),
                        EventFile   = array
                    };
                    await CreateEventAsync(temp);

                    hold.Close();
                    return(View("Events"));

                    //}
                }
                return(View("Events"));
            }
            catch (Exception e)
            {
                string message    = e.Message;
                string stackTrace = e.StackTrace;
                HttpContext.Session.SetString("_Error", "true");
                HttpContext.Session.SetString("_ErrorMessage", message);
                HttpContext.Session.SetString("_ErrorTrace", stackTrace);
                return(View("Error"));
            }
        }
Esempio n. 9
0
        public Event Create(EventIn events)
        {
            Event eventIn = new Event()
            {
                VideoURL    = events.VideoURL,
                Name        = events.Name,
                Location    = events.Location,
                Date        = events.Date,
                TimeStart   = events.TimeStart,
                TimeEnd     = events.TimeEnd,
                EventFileID = UploadFile(events.EventFile, events.Location, events.Date)
            };

            _event.InsertOne(eventIn);
            return(eventIn);
        }
Esempio n. 10
0
        public ActionResult <Event> Post([FromBody] EventIn events)
        {
            try
            {
                Event temp = _eventService.Create(events);

                return(CreatedAtRoute("GetEvent", new { id = temp.Id.ToString() }, temp));
            }
            catch (Exception e)
            {
                string message    = e.Message;
                string stackTrace = e.StackTrace;

                return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError));
            }
        }
Esempio n. 11
0
        public async Task <IActionResult> ViewEvent(String id)
        {
            try
            {
                EventIn event1 = await GetEventAsync("https://localhost:44389/api/1.0/event/" + id);

                return(RedirectToAction("EventRegister", event1));
            }
            catch (Exception e)
            {
                string message    = e.Message;
                string stackTrace = e.StackTrace;
                HttpContext.Session.SetString("_Error", "true");
                HttpContext.Session.SetString("_ErrorMessage", message);
                HttpContext.Session.SetString("_ErrorTrace", stackTrace);
                return(View("Error"));
            }
        }
Esempio n. 12
0
        public EventIn Get(string id)
        {
            Event    events = _event.Find <Event>(tempEvent => tempEvent.Id == id).FirstOrDefault();
            ObjectId temp   = ObjectId.Parse(events.EventFileID);
            var      x      = bucket.DownloadAsBytesAsync(temp);

            Task.WaitAll(x);
            EventIn eventIn = new EventIn()
            {
                Id          = events.Id,
                VideoURL    = events.VideoURL,
                Name        = events.Name,
                Location    = events.Location,
                Date        = events.Date,
                TimeStart   = events.TimeStart,
                TimeEnd     = events.TimeEnd,
                Description = events.Description,
                EventFile   = x.Result
            };

            return(eventIn);
        }
Esempio n. 13
0
        /*public async Task<IActionResult> GetDownload(Download download) {
         *  string hold = download.Id;
         *  //await Download(hold);
         *  return View("Events");
         * }*/

        /// <summary>
        /// This function is the first part of two that allows for the creation
        /// of an Event by the Admin
        /// </summary>
        /// <param name="events"></param>
        /// <returns>
        /// Returns the view update which will handle file uploading.
        /// Should anything go wrong it will send the user to the Error page.
        /// </returns>
        public ActionResult EventRegister(EventIn events)
        {//This must be an async task
            try
            {
                HttpContext.Session.SetString("_VideoURL", events.VideoURL);
                HttpContext.Session.SetString("_EventName", events.Name);
                HttpContext.Session.SetString("_Date", events.Date);
                HttpContext.Session.SetString("_Location", events.Location);
                HttpContext.Session.SetString("_TimeStart", events.TimeStart);
                HttpContext.Session.SetString("_TimeEnd", events.TimeEnd);
                HttpContext.Session.SetString("_Description", events.Description);
                return(View("upload"));
            }
            catch (Exception e)
            {
                string message    = e.Message;
                string stackTrace = e.StackTrace;
                HttpContext.Session.SetString("_Error", "true");
                HttpContext.Session.SetString("_ErrorMessage", message);
                HttpContext.Session.SetString("_ErrorTrace", stackTrace);
                return(View("Error"));
            }
        }