public Infrastructure.ApiResponse <Services.ViewModel.VideoViewModel> Post([FromBody] Services.ViewModel.VideoViewModel model) { var response = new Infrastructure.ApiResponse <Services.ViewModel.VideoViewModel>(); try { var req = new Services.Message.AddVideoRequest(); req.video = model; _videoService.AddVideo(req); response.status = true; response.data = model; response.code = System.Net.HttpStatusCode.Created; } catch (Infrastructure.BusinessRuleException bex) { response.status = true; response.code = System.Net.HttpStatusCode.BadRequest; response.brokenRules = bex.BrokenRules; response.error_message = bex.Message; } catch (Exception ex) { response.status = true; response.code = System.Net.HttpStatusCode.InternalServerError; response.error_message = "Ocorreu um erro inesperado. Entre em contato com o nosso time de desenvolvimento."; } return(response); }
public async Task <IActionResult> SaveMedia([Bind("Id,name,url,views,order,sambatech_id,freeVideo,courseId,schoolId,categoriesId")] Services.ViewModel.VideoViewModel model) { var sambatechresponse = await ApiRequestHelper.Get <EscolaDeVoce.Backend.ViewModel.VideoSambatech>("http://api.sambavideos.sambatech.com/v1/medias/" + model.sambatech_id + "?access_token=181e463a-034b-4ea5-878b-cea906a5f2e2&pid=6023"); EscolaDeVoce.Services.ViewModel.VideoViewModel response = null; model.thumbs = new List <EscolaDeVoce.Services.ViewModel.ThumbViewModel>(); model.files = new List <EscolaDeVoce.Services.ViewModel.FileViewModel>(); foreach (var v in sambatechresponse.files) { EscolaDeVoce.Services.ViewModel.FileViewModel fl = new EscolaDeVoce.Services.ViewModel.FileViewModel(); fl.fileName = v.fileName; fl.url = v.url; fl.id = v.id; model.files.Add(fl); } foreach (var th in sambatechresponse.thumbs) { EscolaDeVoce.Services.ViewModel.ThumbViewModel thumb = new EscolaDeVoce.Services.ViewModel.ThumbViewModel(); thumb.height = th.height; thumb.width = th.width; thumb.url = th.url; model.thumbs.Add(thumb); } System.Net.Http.HttpMethod method = System.Net.Http.HttpMethod.Post; response = await ApiRequestHelper.postPutRequest <EscolaDeVoce.Services.ViewModel.VideoViewModel>( Helpers.EscolaDeVoceEndpoints.Videos.video, method, JsonConvert.SerializeObject(model) ); return(View()); }
public Infrastructure.ApiResponse <Services.ViewModel.VideoViewModel> Put(string id, [FromBody] Services.ViewModel.VideoViewModel model) { var response = new Infrastructure.ApiResponse <Services.ViewModel.VideoViewModel>(); try { Guid videoid = Guid.Empty; if (!Guid.TryParse(id, out videoid)) { return(Infrastructure.ApiResponse <Services.ViewModel.VideoViewModel> .CreateResponse(false, "Video não encontrado", null, System.Net.HttpStatusCode.NotFound)); } model.Id = videoid; _videoService.UpdateVideo(new Services.Message.UpdateVideoRequest() { video = model }); response.status = true; response.data = model; response.code = System.Net.HttpStatusCode.Created; } catch (Infrastructure.BusinessRuleException bex) { response.status = true; response.code = System.Net.HttpStatusCode.BadRequest; response.brokenRules = bex.BrokenRules; response.error_message = bex.Message; } catch (Exception ex) { response.status = true; response.code = System.Net.HttpStatusCode.InternalServerError; response.error_message = "Ocorreu um erro inesperado. Entre em contato com o nosso time de desenvolvimento."; } return(response); }