public IActionResult EditVideo(int id) { var video = _videos.GetById(id); var video_model = new VideoDetailModel { AssetId = id, Title = video.Title, Year = video.Year, Cost = video.Cost, Status = video.Status.Name, NumberOfCopies = video.NumberOfCopies, ImageUrl = video.ImageUrl, AuthorOrDirector = video.Director }; //return Content(mess); return(View(video_model)); }
public IActionResult UpdateVideo(VideoDetailModel asset, IFormFile ImageUrl) { string message = ""; var data = _videos.GetById(asset.AssetId); if (ImageUrl != null) { asset.ImageUrl = "/images/assets/" + ImageUrl.FileName; data.ImageUrl = asset.ImageUrl; var fileName = Path.Combine(he.WebRootPath + "/images/assets", Path.GetFileName(ImageUrl.FileName)); ImageUrl.CopyTo(new FileStream(fileName, FileMode.Create)); } if (ModelState.IsValid) { data.Title = asset.Title; data.Director = asset.AuthorOrDirector; data.NumberOfCopies = asset.NumberOfCopies; data.Year = asset.Year; data.Cost = asset.Cost; bool result = _videos.Update(data); if (result) { message += "Successfully"; } else { message += "Result return false"; } } else { message += "Fail to update"; } // return Content(message); return(RedirectToAction("ListVideo")); }
public async Task InsertOneAsync(VideoDetailModel model) { await _videoDetailRepo.InsertOneAsync(model); }
public async Task StreamingPipelineAsync(IVideoDetailService videoDetailService, string Id, string Token) { try { await _facebookApi.VideoStreamingAsync(Id, Token, async (body) => { PageInfoResponse objPageInfo = await _facebookApi.GetPageInfoAsync(Token); var lstCategory = new List <CategoryModel>(); foreach (var catergory in objPageInfo.Categories) { lstCategory.Add(new CategoryModel() { CategoryId = catergory.CategoryId, CategoryName = catergory.CategoryName }); } PageModel model = new PageModel() { PageId = objPageInfo.PageId, PageName = objPageInfo.PageName, Categories = lstCategory, About = objPageInfo.About, Address = objPageInfo.Address, Link = objPageInfo.Link, Emails = objPageInfo.Emails, Website = objPageInfo.Website, FanCount = objPageInfo.FanCount, CheckinCount = objPageInfo.CheckinCount, CanCheckin = objPageInfo.CanCheckin, NewLikeCount = objPageInfo.NewLikeCount, CanPost = objPageInfo.CanPost, Videos = new List <VideoModel>() }; var pagesModel = _pageRepository.FindAsync(() => Builders <PageModel> .Filter.Eq("PageId", objPageInfo.PageId)).Result.FirstOrDefault(); if (pagesModel == null) { await _pageRepository.InsertOneAsync(model); } List <string> lstPhone = new List <string>(); ReplyTemplateModel replyTemplate = new ReplyTemplateModel(); bool IsSendWhenDetectedPhone = false; bool IsSendWhenDetectedGoodWord = false; bool IsDeleteWhenDetectedBadWord = false; bool IsHidden = false; bool IsHiddenWhenNegSentiment = false; bool IsSendWhenDetectedPhoneResult = false; bool IsSendWhenDetectedGoodWordResult = false; bool IsDeleteWhenDetectedBadWordResult = false; bool IsHiddenResult = false; Match objBadWord = null; Match objGoodWord = null; VideoDetailModel videoModel = null; List <string> lstBadWord = null; List <string> lstGoodWord = null; if (pagesModel.Videos != null && pagesModel.Videos.Count > 0) { foreach (var video in pagesModel.Videos) { if (video.VideoId.Equals(Id)) { lstBadWord = video.BadWords; lstGoodWord = video.GoodWords; IsSendWhenDetectedPhone = video.IsSendWhenDetectedPhone; IsSendWhenDetectedGoodWord = video.IsSendWhenDetectedGoodWord; IsDeleteWhenDetectedBadWord = video.IsDeleteWhenDetectedBadWord; IsHidden = video.IsHidden; IsHiddenWhenNegSentiment = video.IsHiddenWhenNegSentiment; replyTemplate = video.ReplyTemplate; replyTemplate.Recipient.CommentId = body.Id; break; } } } //1. Detect phone number. foreach (Match phone in Regex.Matches(body.Message.Trim(), @"0\d{9}")) { lstPhone.Add(phone.Value); } if (lstPhone != null && lstPhone.Count > 0) { if (IsSendWhenDetectedPhone == true) { IsSendWhenDetectedPhoneResult = await _facebookApi.SendPrivateReplyAsync(replyTemplate.ToModelReq(), Token); } if (IsHidden == true && IsHiddenResult == false) { //IsHiddenResult = await _facebookApi.HiddenCommentAsync(body.Id, Token, true); IsHiddenResult = await _facebookApi.DeleteCommentAsync(body.Id, Token); } } //2. Sentiment NLP if (IsHiddenWhenNegSentiment && IsHiddenResult == false) { if (_sentimentNLPApi.SentimentNLP(body.Message.Trim()).Result) { //IsHiddenResult = await _facebookApi.HiddenCommentAsync(body.Id, Token, true); IsHiddenResult = await _facebookApi.DeleteCommentAsync(body.Id, Token); } } //3. Detect bad word and delete comment. if (lstBadWord != null) { if (IsDeleteWhenDetectedBadWord == true) { foreach (string badWord in lstBadWord) { objBadWord = Regex.Match(body.Message.Trim().ToLower(), badWord.Trim().ToLower()); if (objBadWord.Success) { IsDeleteWhenDetectedBadWordResult = await _facebookApi.DeleteCommentAsync(body.Id, Token); } } } } //4. Detect good word and send private reply if (lstGoodWord != null) { if (IsSendWhenDetectedGoodWord == true) { foreach (string goodWord in lstGoodWord) { objGoodWord = Regex.Match(body.Message.Trim().ToLower(), goodWord.Trim().ToLower()); if (objGoodWord.Success) { IsSendWhenDetectedGoodWordResult = await _facebookApi.SendPrivateReplyAsync(replyTemplate.ToModelReq(), Token); } } } } //5. Insert or Update new document. videoModel = videoDetailService.FindAsync(() => Builders <VideoDetailModel> .Filter.Eq("FbId", body.From.Id)).Result.FirstOrDefault(); var commentModel = new CommentModel() { CommentId = body.Id, Message = body.Message, IsSendWhenDetectedPhoneResult = IsSendWhenDetectedPhoneResult, IsSendWhenDetectedGoodWordResult = IsSendWhenDetectedGoodWordResult, IsDeleteWhenDetectedBadWordResult = IsDeleteWhenDetectedBadWordResult, IsHiddenResult = IsHiddenResult, CreatedTime = body.CreatedTime }; if (videoModel == null) { videoModel = new VideoDetailModel(); videoModel.FbId = body.From.Id; videoModel.FbName = body.From.Name; videoModel.Phones = lstPhone; videoModel.Comments.Add(commentModel); await videoDetailService.InsertOneAsync(videoModel); } else { if (lstPhone != null && lstPhone.Count > 0) { foreach (string phone in lstPhone) { videoModel.Phones.Add(phone); } } videoModel.Comments.Add(commentModel); await videoDetailService.UpdateOneAsync(() => Builders <VideoDetailModel> .Filter.Eq("FbId", body.From.Id), () => Builders <VideoDetailModel> .Update.Set("Comments", videoModel.Comments).Set("Phones", videoModel.Phones)); } }); } catch (HttpRequestException ex) { throw ex; } catch (Exception ex) { throw ex; } }