public async Task <ActionResult <dynamic> > FindServerById(string serverId) { var response = await _serverServices.FindServerById(serverId); if (!response.Success) { return(BadRequest(new ProblemDetails() { Type = "https://httpstatuses.com/400", Title = ReasonPhrases.GetReasonPhrase(400), Status = 400, Detail = response.Message })); } return(Ok()); }
public async Task <CreateVideoResponse> AddVideo(string serverId, CreateVideoResource video) { try { var server = await _serverServices.FindServerById(serverId); if (!server.Success) { return(new CreateVideoResponse("Server not found")); } if (await FindVideo(video, serverId) == true) { return(new CreateVideoResponse("Video já inserido no servidor")); } var encoded = Regex.Replace(video.VideoBase64, @"data:video\/.{3,7};base64,", String.Empty); encoded = encoded.Replace("data:application/pdf;base64,", String.Empty); var type = Regex.Replace(video.VideoBase64, @";.*", String.Empty); var contentType = type.Replace("data:", ""); // var type = Regex.Replace(image, @";.*", String.Empty); byte[] ret = Convert.FromBase64String(encoded); var model = _mapper.Map <CreateVideoResource, Videos>(video); model.ServerId = server.Server.Id; model.sizeInBytes = ret.Length; model.Id = Guid.NewGuid().ToString(); await _dataContext.Videos.AddAsync(model); await _dataContext.SaveChangesAsync(); return(new CreateVideoResponse(model)); } catch (Exception ex) { return(new CreateVideoResponse(ex.Message)); } }