Beispiel #1
0
        //[ValidateAntiForgeryToken]
        public EventDownload UploadFile(IFormFile file, [FromRoute] int id)
        {
            if (file.Length <= 0)
            {
                return(null);
            }

            using (var client = new System.Net.Http.HttpClient())
            {
                // Upload File
                long?fileId = Services.Storages.Files.NewFile(this._storageSettings, file);
                if (!fileId.HasValue)
                {
                    return(null);
                }

                Models.EventDownload newDownload = new EventDownload();

                newDownload.EventId = id;
                newDownload.StorageServiceFileId = fileId.Value;
                System.Text.RegularExpressions.Regex regexFileName = new System.Text.RegularExpressions.Regex(@".*(?=\.\w+$)");
                newDownload.Name = regexFileName.Match(file.FileName).Value;

                newDownload = Services.Events.Downloads.CreateDownload(this._eventSettings, newDownload);

                // TODO Im Fehlerfall Datei wieder löschen
                if (newDownload == null)
                {
                    Services.Storages.Files.DeleteFile(this._storageSettings, fileId.Value);
                }

                return(newDownload);
            }
        }
Beispiel #2
0
        public static FileStream GetFileStream(EventServiceConfiguration settingsEventService, StorageServiceConfiguation settingsStorrageService, long downloadId)
        {
            EventDownload download = null;

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(settingsEventService.BaseUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                client.DefaultRequestHeaders.Add("api-version", "1.0");
                HttpResponseMessage response = client.GetAsync(settingsEventService.ResourceRoot + "/downloads/" + downloadId.ToString()).Result;
                if (response.IsSuccessStatusCode)
                {
                    string stringData = response.Content.ReadAsStringAsync().Result;
                    download = JsonConvert.DeserializeObject <EventDownload>(stringData);
                }
            }

            if (download == null)
            {
                return(null);
            }

            return(Services.Storages.Files.GetFileStream(settingsStorrageService, download.StorageServiceFileId));
        }
        public bool Delete(int id)
        {
            EventDownload download = Services.Events.Downloads.ReadDownload(this._eventSettings, id);

            Services.Events.Downloads.DeleteDownload(this._eventSettings, id);

            Services.Storages.Files.DeleteFile(this._storageSettings, download.StorageServiceFileId);
            return(true);
        }
 // [ValidateAntiForgeryToken]
 public EventDownload PutDownload([FromRoute] int id, [FromBody] EventDownload downloadToEdit)
 {
     try
     {
         EventDownload result = Services.Events.Downloads.UpdateDownload(this._eventSettings, downloadToEdit);
         return(result); // RedirectToAction("Index");
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
 //[ValidateAntiForgeryToken]
 public EventDownload PostDownload([FromBody] EventDownload newDownload)
 {
     try
     {
         EventDownload result = Services.Events.Downloads.CreateDownload(this._eventSettings, newDownload);
         return(result);
     }
     catch
     {
         return(null);
     }
 }
Beispiel #6
0
        public static EventDownload UpdateDownload(EventServiceConfiguration settings, EventDownload downloadToUpdate)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(settings.BaseUrl);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                client.DefaultRequestHeaders.Add("api-version", "1.0");

                var stringContent = new StringContent(JsonConvert.SerializeObject(downloadToUpdate),
                                                      Encoding.UTF8,
                                                      "application/json");

                HttpResponseMessage response = client.PutAsync(settings.ResourceRoot + "/downloads/" + downloadToUpdate.DownloadId.ToString(), stringContent).Result;
                if (response.IsSuccessStatusCode)
                {
                    string stringData = response.Content.ReadAsStringAsync().Result;
                    return(JsonConvert.DeserializeObject <EventDownload>(stringData));
                }
            }

            return(null);
        }