示例#1
0
        public async Task <ActionResultResponse> Update(string tenantId, string lastUpdateUserId, string lastUpdateFullName, string lastUpdateAvata, string videoId, VideoMeta videoMeta)
        {
            var apiUrls = _configuration.GetApiUrl();

            if (apiUrls == null)
            {
                return(new ActionResultResponse <string>(-5,
                                                         _sharedResourceService.GetString(
                                                             "Missing some configuration. Please contact with administrator.")));
            }
            var videoTags = new List <TagSubjectViewModel>();

            var info = await _videoRepository.GetInfo(videoId);

            if (info == null)
            {
                return(new ActionResultResponse(-1, _websiteResourceService.GetString("Video does not exists.")));
            }

            if (info.TenantId != tenantId)
            {
                return(new ActionResultResponse(-2, _sharedResourceService.GetString(ErrorMessage.NotHavePermission)));
            }

            if (info.ConcurrencyStamp != videoMeta.ConcurrencyStamp)
            {
                return(new ActionResultResponse(-3, _websiteResourceService.GetString("The video already updated by other people. You can not update this video.")));
            }

            info.AlbumId            = videoMeta.AlbumId;
            info.Thumbnail          = videoMeta.Thumbnail;
            info.Url                = videoMeta.Url;
            info.VideoLinkId        = videoMeta.VideoLinkId;
            info.Type               = videoMeta.Type;
            info.Order              = videoMeta.Order;
            info.IsActive           = videoMeta.IsActive;
            info.ConcurrencyStamp   = Guid.NewGuid().ToString();
            info.LastUpdate         = DateTime.Now;
            info.LastUpdateUserId   = lastUpdateUserId;
            info.LastUpdateFullName = lastUpdateFullName;

            if (videoMeta.IsHomePage.HasValue)
            {
                info.IsHomePage           = videoMeta.IsHomePage.Value;
                info.LastUpdateIsHomePage = DateTime.Now;
            }
            //udpate translate
            foreach (var videoTranslation in videoMeta.Translations)
            {
                var isNameExists = await _videoTranslationRepository.CheckExists(info.Id, tenantId,
                                                                                 videoTranslation.LanguageId, videoTranslation.Title);

                if (isNameExists)
                {
                    return(new ActionResultResponse(-4, _websiteResourceService.GetString("Video name: \"{0}\" already exists.", videoTranslation.Title)));
                }

                var videoTranslationInfo =
                    await _videoTranslationRepository.GetInfo(info.Id, videoTranslation.LanguageId);

                if (videoTranslationInfo != null)
                {
                    videoTranslationInfo.Title       = videoTranslation.Title.Trim();
                    videoTranslationInfo.Description = videoTranslation.Description?.Trim();
                    videoTranslationInfo.UnsignName  = videoTranslation.Title.StripVietnameseChars().ToUpper();
                    await _videoTranslationRepository.Update(videoTranslationInfo);
                }
                else
                {
                    var videoTranslationInsert = new VideoTranslation
                    {
                        VideoId     = videoId,
                        LanguageId  = videoTranslation.LanguageId.Trim(),
                        Title       = videoTranslation.Title.Trim(),
                        Description = videoTranslation.Description?.Trim(),
                        UnsignName  = videoTranslation.Title.StripVietnameseChars().ToUpper()
                    };
                    await _videoTranslationRepository.Insert(videoTranslationInsert);
                }

                var videoTagInsert = new TagSubjectViewModel
                {
                    TenantId        = tenantId,
                    CreatorId       = lastUpdateUserId,
                    CreatorFullName = lastUpdateFullName,
                    CreatorAvata    = lastUpdateAvata,
                    Type            = TagType.Video,
                    SubjectId       = videoId,
                    LanguageId      = videoTranslation.LanguageId.Trim(),
                    Tags            = videoTranslation.Tags
                };
                videoTags.Add(videoTagInsert);
            }

            var resultTag = await new HttpClientService()
                            .PostAsync <ActionResultResponse>($"{apiUrls.CoreApiUrl}/tags", videoTags);

            return(new ActionResultResponse(1, _websiteResourceService.GetString("Update video successful.")));
        }
示例#2
0
        public async Task <ActionResultResponse <string> > Insert(string tenantId, string creatorId, string creatorFullName, string creatorAvata, VideoMeta videoMeta)
        {
            var videoId = Guid.NewGuid().ToString();
            // Insert new video.
            var video = new Video
            {
                Id               = videoId,
                AlbumId          = videoMeta.AlbumId,
                ConcurrencyStamp = videoId,
                Thumbnail        = videoMeta.Thumbnail,
                Url              = videoMeta.Url,
                Order            = videoMeta.Order,
                Type             = videoMeta.Type,
                VideoLinkId      = videoMeta.VideoLinkId,
                IsActive         = videoMeta.IsActive,
                TenantId         = tenantId,
                CreatorId        = creatorId,
                CreatorFullName  = creatorFullName
            };

            if (videoMeta.IsHomePage.HasValue)
            {
                video.IsHomePage           = videoMeta.IsHomePage.Value;
                video.LastUpdateIsHomePage = DateTime.Now;
            }

            var resultInsertVideo = await _videoRepository.Insert(video);

            if (resultInsertVideo <= 0)
            {
                return(new ActionResultResponse <string>(resultInsertVideo,
                                                         _sharedResourceService.GetString(ErrorMessage.SomethingWentWrong)));
            }

            #region insert video Translation.

            if (videoMeta.Translations.Count > 0)
            {
                var resultInsertTranslation = await InsertVideoTranslation();

                if (resultInsertTranslation.Code <= 0)
                {
                    return(resultInsertTranslation);
                }
            }
            #endregion

            return(new ActionResultResponse <string>(1,
                                                     _websiteResourceService.GetString("Add new video successful."),
                                                     string.Empty, videoId));


            #region Local functions

            async Task <ActionResultResponse <string> > InsertVideoTranslation()
            {
                var apiUrls = _configuration.GetApiUrl();

                if (apiUrls == null)
                {
                    return(new ActionResultResponse <string>(-5,
                                                             _sharedResourceService.GetString(
                                                                 "Missing some configuration. Please contact with administrator.")));
                }

                var videoTranslations = new List <VideoTranslation>();
                var videoTags         = new List <TagSubjectViewModel>();

                foreach (var videoTranslation in videoMeta.Translations)
                {
                    // Check name exists.
                    var isNameExists = await _videoTranslationRepository.CheckExists(videoId, tenantId,
                                                                                     videoTranslation.LanguageId, videoTranslation.Title);

                    if (isNameExists)
                    {
                        await RollbackInsertVideo();

                        return(new ActionResultResponse <string>(-2, _websiteResourceService.GetString(
                                                                     "Video name: \"{0}\" already exists.",
                                                                     videoTranslation.Title)));
                    }

                    var videoTranslationInsert = new VideoTranslation
                    {
                        TenantId    = tenantId,
                        VideoId     = videoId,
                        LanguageId  = videoTranslation.LanguageId.Trim(),
                        Title       = videoTranslation.Title.Trim(),
                        Description = videoTranslation.Description?.Trim(),
                        UnsignName  = videoTranslation.Title.StripVietnameseChars().ToUpper()
                    };

                    videoTranslations.Add(videoTranslationInsert);

                    var videoTagInsert = new TagSubjectViewModel
                    {
                        TenantId        = tenantId,
                        CreatorId       = creatorId,
                        CreatorFullName = creatorFullName,
                        CreatorAvata    = creatorAvata,
                        Type            = TagType.Video,
                        SubjectId       = videoId,
                        LanguageId      = videoTranslation.LanguageId.Trim(),
                        Tags            = videoTranslation.Tags
                    };
                    videoTags.Add(videoTagInsert);
                }
                var resultTag = await new HttpClientService()
                                .PostAsync <ActionResultResponse>($"{apiUrls.CoreApiUrl}/tags", videoTags);

                // Insert video translations.
                var resultInsertTranslation = await _videoTranslationRepository.Inserts(videoTranslations);

                if (resultInsertTranslation > 0)
                {
                    return(new ActionResultResponse <string>(1,
                                                             _websiteResourceService.GetString("Add new video translation successful."), string.Empty,
                                                             videoId));
                }

                await RollbackInsertVideoTranslation();
                await RollbackInsertVideo();

                return(new ActionResultResponse <string>(-3,
                                                         _websiteResourceService.GetString(
                                                             "Can not insert new video. Please contact with administrator.")));
            }

            async Task RollbackInsertVideo()
            {
                await _videoRepository.ForceDelete(videoId);
            }

            async Task RollbackInsertVideoTranslation()
            {
                await _videoTranslationRepository.ForceDelete(videoId);
            }

            #endregion
        }
示例#3
0
 public async Task <int> Update(VideoTranslation videoTranslation)
 {
     return(await Context.SaveChangesAsync());
 }
示例#4
0
 public async Task <int> Insert(VideoTranslation videoTranslation)
 {
     _videoTranslationRepository.Create(videoTranslation);
     return(await Context.SaveChangesAsync());
 }
示例#5
0
 public int NewVideoTranslation(DateTime dtTimeBegin, DateTime dtTimeTranslation, string nvTranslatorIdentity, string nvUserIdentity)
 {
     return(VideoTranslation.NewVideoTranslation(dtTimeBegin, dtTimeTranslation, nvTranslatorIdentity, nvUserIdentity));
 }
示例#6
0
 public double GetCommunicationBalance(string nvIdentity)
 {
     return(VideoTranslation.GetCommunicationBalance(nvIdentity));
 }
示例#7
0
 public double GetNumHours(string nvIdentity)
 {
     return(VideoTranslation.GetNumHours(nvIdentity));
 }