public async Task <IActionResult> AddVideoAndRemoveItFromRequested(VideoViewModel input, string userId) { var user = await userManager.FindByIdAsync(userId); await videoService.AddVideoAsync(input.Link, input.Title, input.Description, userId); await requestedVideoService.RemoveRequestedVideoAsync(input.Id); await emailSender.SendEmailAsync(user.Email, "Your Video:", GlobalConstants.MessageForGoodVideo); await messageService.AddMessageToUserAsync(GlobalConstants.MessageForGoodVideo, userId, null); return(Redirect("/Administration/RequestedVideo/AllRequestedVideos")); }
public async Task <ActionResult> AddVideoAsync([FromBody] VideoDTO videoDto, [BindRequired] Guid id) { try { byte[] videoBytes = Convert.FromBase64String(videoDto.File.Trim()); string guid = Guid.NewGuid().ToString("n"), directory = Directory.GetCurrentDirectory() + "/videos/", path = "", video = "", guidFormated = string.Format("{0}-{1}-{2}", guid.Substring(0, 4), guid.Substring(5, 4), guid.Substring(8, 4)); if (!Directory.Exists(_environment.WebRootPath + directory)) { Directory.CreateDirectory(_environment.WebRootPath + directory); } video = $"vid_{guidFormated}.mp4"; path = $"{directory}{video}"; using (var fs = System.IO.File.Create(_environment.WebRootPath + directory + video)) { using (var bw = new BinaryWriter(fs)) { bw.Write(videoBytes); videoDto.Size = (int)bw.BaseStream.Length; videoDto.FileName = video; bw.Close(); } } if (!String.IsNullOrEmpty(path)) { var videoResult = await _videoService.AddVideoAsync(videoDto); return(new ObjectResult(videoResult)); } else { return(BadRequest($"Error when try to add a new video on server")); } } catch (Exception ex) { return(BadRequest($"Error when try to add a new video on server: {ex.Message}")); } }
public async Task <ActionResult <Video> > Post([FromBody] Video newVideo) //async Task<ActionResult< { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Video video = await _videoService.FindVideoAsync(newVideo.VideoId); if (video != null) { return(StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status409Conflict, new { message = "Видео \"" + video.Title + "\" уже существует" })); } _videoService.AddVideoAsync(newVideo); await _videoService.SaveChangesAsync(); //return CreatedAtAction(nameof(Get), new { id = newVideo.id }, newVideo); return(Ok("Видео успешно добавлено")); }