示例#1
0
        public IHttpActionResult SaveWorkFlowDetails(WorkFlowAc workFlowDetails)
        {
            try
            {
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    var userId         = HttpContext.Current.User.Identity.GetUserId();
                    var companyDetails = _companyDataRepository.FirstOrDefault(x => x.UserId == userId);
                    if (companyDetails != null)
                    {
                        foreach (var workFlow in workFlowDetails.Permission)
                        {
                            if (workFlow != null)
                            {
                                if (workFlow.IsApproval || workFlow.IsReview || workFlow.IsClosed || workFlow.IsCondition)
                                {
                                    var workFlowDetail = new WorkFlowDetail
                                    {
                                        WorkFlowName = workFlowDetails.WorkFlowName,
                                        WorkFlowId   = workFlowDetails.PermissionId,
                                        InitiatorId  = workFlow.InitiatorId,
                                        AssignedId   = workFlow.AssignedId,
                                        //OldStatusId = workFlow.OldStatus,
                                        //NewStatusId = workFlow.NewStatus,
                                        //CreatedDateTime = DateTime.UtcNow,
                                        CreatedBy  = HttpContext.Current.User.Identity.GetUserId(),
                                        IsApproval = workFlow.IsApproval,
                                        IsReview   = workFlow.IsReview,
                                        // WorkFlowActionId = workFlow.ActionId,
                                        CompanyId      = companyDetails.Id,
                                        ActivityId     = workFlow.ActivityId,
                                        NextActivityId = workFlow.NextActivityId,
                                        IsClosed       = workFlow.IsClosed,
                                        IsParentAction = true,
                                        Id             = workFlowDetails.workFlowActionId,
                                        //Variable1 = workFlow.Variable1,
                                        //Variable2 = workFlow.Variable2,
                                        //Operator = workFlow.Operator,
                                        IsCondition            = workFlow.IsCondition,
                                        IsAllowOtherBranchUser = workFlow.IsAllowOtherBranchUser,
                                        ParentActivityId       = 0,
                                    };
                                    IsChildCondtion   = workFlowDetail.IsCondition;
                                    _parentActivityId = _workFlowRepository.SaveWorkFlowActionDetails(workFlowDetail);
                                    if (workFlow.IsCondition)
                                    {
                                        foreach (var workFlowConditionalOperator in workFlow.ConditionalOperator)
                                        {
                                            //if (workFlowConditionalOperator.ConditionInfo == null)
                                            //{
                                            var conditionlOperator = new ConditionalOperator
                                            {
                                                Id        = workFlowConditionalOperator.ConditionalOperatorId,
                                                Variable1 = workFlowConditionalOperator.Variable1,
                                                Variable2 = workFlowConditionalOperator.Variable2,
                                                Condition = workFlowConditionalOperator.ConditionInfo,
                                                //CreatedDateTime = DateTime.UtcNow,
                                                Operator                    = workFlowConditionalOperator.Operator,
                                                WorkFlowDetailId            = _parentActivityId,
                                                IsBoolenCondtion            = workFlowConditionalOperator.IsBoolenCondtion,
                                                ParentConditionalOperatorId = _conditionalOperatorParentId
                                            };

                                            _conditionalOperatorParentId = _workFlowRepository.SaveWorkConditionalOperatorDetails(conditionlOperator);
                                            // }
                                            //else
                                            //{
                                            //    var conditionlOperator = new ConditionalOperator
                                            //    {
                                            //        Id = workFlowConditionalOperator.ConditionalOperatorId,
                                            //        Variable1 = workFlowConditionalOperator.Variable1,
                                            //        Variable2 = workFlowConditionalOperator.Variable2,
                                            //        Condition = workFlowConditionalOperator.ConditionInfo,
                                            //        CreatedDateTime = DateTime.UtcNow,
                                            //        Operator = workFlowConditionalOperator.Operator,
                                            //        WorkFlowDetailId = _parentActivityId,
                                            //        ParentConditionalOperatorId = _conditionalOperatorParentId
                                            //    };
                                            //    _conditionalOperatorChildId =
                                            //        _workFlowRepository.SaveWorkConditionalOperatorDetails(conditionlOperator);
                                            //}
                                        }
                                    }
                                }
                                else
                                {
                                    var workFlowDetail = new WorkFlowDetail
                                    {
                                        // WorkFlowName = workFlowDetails.WorkFlowName,
                                        WorkFlowId  = workFlowDetails.PermissionId,
                                        InitiatorId = workFlow.InitiatorId,
                                        AssignedId  = workFlow.AssignedId,
                                        //OldStatusId = workFlow.OldStatus,
                                        //NewStatusId = workFlow.NewStatus,
                                        //CreatedDateTime = DateTime.UtcNow,
                                        CreatedBy  = HttpContext.Current.User.Identity.GetUserId(),
                                        IsApproval = workFlow.IsApproval,
                                        IsReview   = workFlow.IsReview,
                                        // WorkFlowActionId = workFlow.ActionId,
                                        CompanyId            = companyDetails.Id,
                                        ActivityId           = workFlow.ActivityId,
                                        NextActivityId       = workFlow.NextActivityId,
                                        IsClosed             = workFlow.IsClosed,
                                        IsApprovePanel       = workFlow.IsApprovePanel,
                                        IsRejectPanel        = workFlow.IsRejectPanel,
                                        ParentActivityId     = _parentActivityId,
                                        IsChildAction        = true,
                                        IsAllowOtherWorkFlow = workFlow.IsAllowOtherWorkFlow,
                                        OtherWorkFlowId      = workFlow.OtherWorkFlowId,
                                        Id = workFlow.workFlowActionId,
                                        IsAllowOtherBranchUser = workFlow.IsAllowOtherBranchUser,
                                        //Variable2 = workFlow.Variable2,


                                        // Variable1 = workFlow.Variable1,

                                        //Operator = workFlow.Operator,
                                        IsCondition      = workFlow.IsCondition,
                                        IsChildCondition = IsChildCondtion,
                                    };
                                    _childActivityId = _workFlowRepository.SaveWorkFlowDetails(workFlowDetail);
                                }
                            }
                        }
                        workFlowDetails.PermissionId = _parentActivityId;
                    }


                    //var workFlowCollection = _workFlowRepository.GetWorkFlowDetailsForTreeViewByActivityId(workFlowDetails.ActivityId);
                    return(Ok(workFlowDetails));
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                _errorLog.LogException(ex);
                throw;
            }
        }