Beispiel #1
0
        public async Task <LabelCloneResponse> CloneLabel(LabelCloneRequest request)
        {
            var response = new LabelCloneResponse();

            var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId);

            if (!currentUser.IsAdmin)
            {
                response.SetInvalid();
                return(response);
            }

            if (await _organizationRepository.Any(x => x.Id == currentUser.OrganizationId && !x.IsActive))
            {
                response.SetInvalid();
                response.ErrorMessages.Add("organization_not_active");
                return(response);
            }

            var label = await _labelRepository.Select(x => x.Uid == request.CloningLabelUid);

            if (label.IsNotExist())
            {
                response.SetInvalid();
                response.ErrorMessages.Add("label_not_found");
                return(response);
            }

            if (label.OrganizationId != currentUser.OrganizationId)
            {
                response.SetInvalid();
                return(response);
            }

            if (await _labelRepository.Any(x => x.Key == request.LabelKey && x.ProjectId == label.ProjectId))
            {
                response.ErrorMessages.Add("label_key_must_be_unique");
                response.Status = ResponseStatus.Failed;
                return(response);
            }

            var newLabel  = _labelFactory.CreateEntityFromRequest(request, label);
            var uowResult = await _labelUnitOfWork.DoCloneWork(request.CurrentUserId, label.Id, newLabel);

            if (uowResult)
            {
                response.Item   = _labelFactory.CreateDtoFromEntity(newLabel);
                response.Status = ResponseStatus.Success;
                return(response);
            }

            response.SetFailed();
            return(response);
        }
Beispiel #2
0
        public Label CreateEntityFromRequest(LabelCloneRequest request, Label label)
        {
            var entity = new Label();

            entity.OrganizationId   = label.OrganizationId;
            entity.OrganizationUid  = label.OrganizationUid;
            entity.OrganizationName = label.OrganizationName;

            entity.ProjectId   = label.ProjectId;
            entity.ProjectUid  = label.ProjectUid;
            entity.ProjectName = label.ProjectName;

            entity.Description = request.Description;
            entity.Key         = request.LabelKey;
            entity.Name        = request.LabelKey;

            entity.IsActive = true;

            return(entity);
        }
Beispiel #3
0
        public async Task <IActionResult> Clone(LabelCloneModel model)
        {
            if (model.IsNotValid())
            {
                model.SetInputModelValues();
                return(View(model));
            }

            var request = new LabelCloneRequest(CurrentUser.Id, model.OrganizationUid, model.CloningLabelUid,
                                                model.ProjectUid, model.Key, model.Description);
            var response = await _labelService.CloneLabel(request);

            if (response.Status.IsNotSuccess)
            {
                model.MapMessages(response);
                model.SetInputModelValues();
                return(View(model));
            }

            CurrentUser.IsActionSucceed = true;
            return(Redirect($"/Label/Detail/{response.Item.Uid}"));
        }
        public static LabelCloneRequest GetLabelCloneRequest()
        {
            var request = new LabelCloneRequest(CurrentUserId, UidOne, UidOne, UidOne, StringOne, StringOne);

            return(request);
        }