Exemplo n.º 1
0
        public async Task <IActionResult> Update(string id, [FromBody] VideoGroupMeta videoGroupMeta)
        {
            var result = await _videoGroupService.Update(CurrentUser.TenantId, CurrentUser.Id, CurrentUser.FullName, CurrentUser.Avatar, id, videoGroupMeta);

            if (result.Code <= 0)
            {
                return(BadRequest(result));
            }
            return(Ok(result));
        }
Exemplo n.º 2
0
        public async Task <ActionResultResponse <string> > Insert(string tenantId, string creatorId, string creatorFullName, string creatorAvata,
                                                                  VideoGroupMeta videoGroupMeta)
        {
            var videoGroupId = Guid.NewGuid().ToString();
            // Insert new video.
            var resultInsertVideoGroup = await _videoGroupRepository.Insert(new VideoGroup
            {
                Id = videoGroupId,
                ConcurrencyStamp = videoGroupId,
                IsActive         = videoGroupMeta.IsActive,
                TenantId         = tenantId,
                CreatorId        = creatorId,
                CreatorFullName  = creatorFullName
            });

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

            #region insert video Group Translation.

            if (videoGroupMeta.VideoGroupTranslations.Count > 0)
            {
                var resultInsertTranslation = await InsertVideoGroupTranslation();

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

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


            #region Local functions

            async Task <ActionResultResponse <string> > InsertVideoGroupTranslation()
            {
                var videoGroupTranslations = new List <VideoGroupTranslation>();

                foreach (var videoGroupTranslation in videoGroupMeta.VideoGroupTranslations)
                {
                    // Check name exists.
                    var isNameExists = await _videoGroupTranslationRepository.CheckExists(videoGroupId, tenantId,
                                                                                          videoGroupTranslation.LanguageId, videoGroupTranslation.Name);

                    if (isNameExists)
                    {
                        await RollbackInsertVideoGroup();

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

                    var videoGroupTranslationInsert = new VideoGroupTranslation
                    {
                        TenantId     = tenantId,
                        VideoGroupId = videoGroupId,
                        LanguageId   = videoGroupTranslation.LanguageId.Trim(),
                        Name         = videoGroupTranslation.Name.Trim(),
                        Description  = videoGroupTranslation.Description?.Trim(),
                        UnsignName   = videoGroupTranslation.Name.StripVietnameseChars().ToUpper()
                    };

                    videoGroupTranslations.Add(videoGroupTranslationInsert);
                }

                // Insert video translations.
                var resultInsertTranslation = await _videoGroupTranslationRepository.Inserts(videoGroupTranslations);

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

                await RollbackInsertVideoGroupTranslation();
                await RollbackInsertVideoGroup();

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

            async Task RollbackInsertVideoGroup()
            {
                await _videoGroupRepository.ForceDelete(videoGroupId);
            }

            async Task RollbackInsertVideoGroupTranslation()
            {
                await _videoGroupTranslationRepository.ForceDelete(videoGroupId);
            }

            #endregion
        }
Exemplo n.º 3
0
        public async Task <ActionResultResponse> Update(string tenantId, string lastUpdateUserId, string lastUpdateFullName, string lastUpdateAvata,
                                                        string videoGroupId, VideoGroupMeta videoGroupMeta)
        {
            var info = await _videoGroupRepository.GetInfo(videoGroupId);

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

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

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


            info.IsActive           = videoGroupMeta.IsActive;
            info.ConcurrencyStamp   = Guid.NewGuid().ToString();
            info.LastUpdate         = DateTime.Now;
            info.LastUpdateUserId   = lastUpdateUserId;
            info.LastUpdateFullName = lastUpdateFullName;

            await _videoGroupRepository.Update(info);

            //udpate translate
            foreach (var videoGroupTranslation in videoGroupMeta.VideoGroupTranslations)
            {
                var isNameExists = await _videoGroupTranslationRepository.CheckExists(info.Id, tenantId,
                                                                                      videoGroupTranslation.LanguageId, videoGroupTranslation.Name);

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

                var videoGroupTranslationInfo =
                    await _videoGroupTranslationRepository.GetInfo(tenantId, videoGroupTranslation.LanguageId, videoGroupId);

                if (videoGroupTranslationInfo != null)
                {
                    videoGroupTranslationInfo.Name        = videoGroupTranslation.Name.Trim();
                    videoGroupTranslationInfo.Description = videoGroupTranslation.Description?.Trim();
                    videoGroupTranslationInfo.UnsignName  = videoGroupTranslation.Name.StripVietnameseChars().ToUpper();
                    await _videoGroupTranslationRepository.Update(videoGroupTranslationInfo);
                }
                else
                {
                    var videoGroupTranslationInsert = new VideoGroupTranslation
                    {
                        VideoGroupId = videoGroupId,
                        LanguageId   = videoGroupTranslation.LanguageId.Trim(),
                        Name         = videoGroupTranslation.Name.Trim(),
                        Description  = videoGroupTranslation.Description?.Trim(),
                        UnsignName   = videoGroupTranslation.Name.StripVietnameseChars().ToUpper()
                    };
                    await _videoGroupTranslationRepository.Insert(videoGroupTranslationInsert);
                }
            }
            return(new ActionResultResponse(1, _websiteResourceService.GetString("Update video group successful.")));
        }