Exemplo n.º 1
0
        public async Task <string> UploadVideo(string location, string beskrivelse, int albumdId)
        {
            client.Client.ReadWriteTimeout = int.MaxValue;
            client.Client.Timeout          = int.MaxValue;
            var video = new PB_Video {
                Beskrivelse = beskrivelse, PB_FotoalbumId = albumdId, Url = $"http://photobook.nillertron.com/video/", OprettetDato = DateTime.Now
            };

            await Task.Run(async() =>
            {
                var rq = new RestRequest("api/Video/upload", Method.POST);
                rq.AddFile("file", location);
                rq.AddHeader("Content-Type", "multipart/form-data");

                var response = await client.Client.ExecuteAsync(rq);

                var status = JsonConvert.DeserializeObject <string>(response.Content);
                if (status == "File null")
                {
                    throw new Exception("No file");
                }
                video.Url += status;
            });

            var created = await SaveVideoToDb(video);

            if (created == "Created")
            {
                return("Created");
            }
            else
            {
                return("Error");
            }
        }
Exemplo n.º 2
0
        public async Task <string> Edit([FromBody] PB_Video video)
        {
            try
            {
                await repo.Edit(video);

                return("Ok");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Exemplo n.º 3
0
        public async Task <string> SaveToDb([FromBody] PB_Video video)
        {
            try
            {
                await repo.Create(video);

                return("Ok");
            }
            catch (Exception e)
            {
                return("not ok");
            }
        }
Exemplo n.º 4
0
        public async Task DeleteVideo(PB_Video video)
        {
            var rq = new RestRequest("api/Video/Delete", Method.POST);
            var s  = JsonConvert.SerializeObject(video);

            rq.AddParameter("application/json; charset=utf-8", s, ParameterType.RequestBody);
            var response = await client.Client.ExecuteAsync(rq);

            var result = JsonConvert.DeserializeObject <string>(response.Content);

            if (result != "Ok")
            {
                throw new Exception(result);
            }
        }
Exemplo n.º 5
0
        public async Task <string> Delete([FromBody] PB_Video video)
        {
            try
            {
                var fileName = video.Url.Replace("http://photobook.nillertron.com/video/", "");
                await repo.Delete(video);

                var fileLocation = Path.Combine(hosting.WebRootPath, "video", fileName);
                System.IO.File.Delete(fileLocation);
                return("Ok");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Exemplo n.º 6
0
        public async Task <string> SaveVideoToDb(PB_Video video)
        {
            string status = string.Empty;
            await Task.Run(async() =>
            {
                var rq = new RestRequest("api/Video/savedb", Method.POST);
                var serialiseretVideo = JsonConvert.SerializeObject(video);
                rq.AddParameter("Application/json; charset=utf-8", serialiseretVideo, ParameterType.RequestBody);
                var response = await client.Client.ExecuteAsync(rq);
                status       = JsonConvert.DeserializeObject <string>(response.Content);
            });

            if (status == "Ok")
            {
                loginState.user.Fotoalbum[video.PB_FotoalbumId].Videos.Insert(0, video);
                return("Created");
            }
            else
            {
                return(status);
            }
        }