Exemplo n.º 1
0
        public async Task <IActionResult> CreateNewProcess(NewProcessFromAPI ProcessesFromAPI)
        {
            var CurrentUser = await _userManager.GetUserAsync(User);

            var       testifallowed = new FrontProcessNewProcessLogic(_userProvider, _processProvider, _frontProcessProvider);
            DataTable ProcessFields = NewProcessField.CreateTable();

            if (await _claimCheck.CheckClaim(CurrentUser, "ApplicationRight", this.ControllerContext.RouteData.Values["controller"].ToString() + "\\" + this.ControllerContext.RouteData.Values["action"].ToString()))              //11
            {
                List <NewProcessTypeList> x = await testifallowed.ReturnProcessTypeList(CurrentUser);

                if (x.Exists(x => x.ProcessTypeId == ProcessesFromAPI.ProcessTypeId))
                {
                    List <FrontProcessNewProcessField> ProcessesFromDB = await _processProvider.CreateGet(CurrentUser.Id, ProcessesFromAPI.ProcessTypeId);

                    int NoOfFields         = ProcessesFromDB.Count();
                    int EqualSequenceCount = 0;
                    if (ProcessesFromDB.Exists(z => z.ProcessTypeStageId == ProcessesFromAPI.ProcessTypeStageId) & ProcessesFromDB.Count() == ProcessesFromAPI.ProcessFields.Count())
                    {
                        foreach (var ProcessFromDB in ProcessesFromDB)
                        {
                            foreach (var ProcessFieldFromAPI in ProcessesFromAPI.ProcessFields)
                            {
                                if (ProcessFieldFromAPI.Sequence == ProcessFromDB.Sequence & ProcessFieldFromAPI.ProcessTypeFieldId == ProcessFromDB.ProcessTypeFieldId)
                                {
                                    EqualSequenceCount++;
                                    switch (ProcessFromDB.ProcessTypeFieldTypeId)
                                    {
                                    case 12:     //User
                                    case 13:     //Sec user
                                        if (!await _checkProvider.CheckUser(ProcessFieldFromAPI.StringValue) & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "User does not exist",
                                            }));
                                        }
                                        break;

                                    case 30:    //role
                                    case 31:    //sec role
                                        if (!await _checkProvider.CheckRole(ProcessFieldFromAPI.StringValue) & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Role does not exist",
                                            }));
                                        }
                                        break;

                                    case 34:     // organization role
                                        if (!await _checkProvider.CheckOrganizationRole(ProcessFieldFromAPI.StringValue) & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Organization role does not exist",
                                            }));
                                        }
                                        break;

                                    case 35:     // project role
                                        if (!await _checkProvider.CheckProjectRole(ProcessFieldFromAPI.StringValue) & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Project role does not exist",
                                            }));
                                        }
                                        break;


                                    case 3:     //Number
                                    case 14:    //Organization
                                    case 15:    //Sec org
                                        if (!await _checkProvider.CheckOrganization((ProcessFieldFromAPI.IntValue ?? 0)) & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Orgnization does not exist",
                                            }));
                                        }
                                        break;

                                    case 16:    //Project
                                    case 17:    //Sec project
                                        if (!await _checkProvider.CheckProject((ProcessFieldFromAPI.IntValue ?? 0)) & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Project does not exist",
                                            }));
                                        }
                                        break;

                                    case 18:    //Language
                                    case 19:    //Sec lang
                                        if (!await _checkProvider.CheckLanguage((ProcessFieldFromAPI.IntValue ?? 0)) & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Language does not exist",
                                            }));
                                        }
                                        break;

                                    case 20:    //Classification
                                    case 21:    //Sec class
                                        if (!await _checkProvider.CheckClassification((ProcessFieldFromAPI.IntValue ?? 0)) & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Classification does not exist",
                                            }));
                                        }
                                        break;

                                    case 22:    //Classification value
                                    case 23:    //Sec class value
                                        if (!await _checkProvider.CheckClassificationValue((ProcessFieldFromAPI.IntValue ?? 0)) & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Classification value does not exist",
                                            }));
                                        }
                                        break;

                                    case 24:    //Content
                                    case 25:    //Sec contentt
                                        if (!await _checkProvider.CheckContent((ProcessFieldFromAPI.IntValue ?? 0)) & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Content does not exist",
                                            }));
                                        }
                                        break;

                                    case 26:    //Country
                                    case 27:    //Sec country
                                        if (!await _checkProvider.CheckCountry((ProcessFieldFromAPI.IntValue ?? 0)) & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Country does not exist",
                                            }));
                                        }
                                        break;

                                    case 28:    //security level
                                    case 29:    //sec security level
                                        if (!await _checkProvider.CheckSecurityLevel((ProcessFieldFromAPI.IntValue ?? 0)) & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Security level does not exist",
                                            }));
                                        }
                                        break;

                                    case 33:     //user has specific relation to user field
                                        if (!await _checkProvider.CheckUserRelation((ProcessFieldFromAPI.IntValue ?? 0)) & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "User relation does not exist",
                                            }));
                                        }
                                        break;
                                        //case 4: //Date
                                        //case 5:
                                        //case 6:
                                        //case 7:
                                        //case 8:
                                        //case 9:

                                        //case 10: //button
                                        //case 11:
                                    }
                                    switch (ProcessFromDB.ProcessTypeFieldTypeId)
                                    {
                                    case 1:     //Text - Subject
                                    case 2:     //text
                                    case 12:    //User
                                    case 13:    //Sec user
                                    case 30:    //role
                                    case 31:    //sec role
                                    case 32:    // html
                                    case 34:    // organization role
                                    case 35:    // project role
                                        if (ProcessFromDB.ProcessTypeStageFieldStatusId == 4 & ProcessFieldFromAPI.StringValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Required value is missing 1",
                                            }));
                                        }

                                        break;

                                    case 3:     //Number
                                    case 14:    //Organization
                                    case 15:    //Sec org
                                    case 16:    //Project
                                    case 17:    //Sec project
                                    case 18:    //Language
                                    case 19:    //Sec lang
                                    case 20:    //Classification
                                    case 21:    //Sec class
                                    case 22:    //Classification value
                                    case 23:    //Sec class value
                                    case 24:    //Content
                                    case 25:    //Sec contentt
                                    case 26:    //Country
                                    case 27:    //Sec country
                                    case 28:    //security level
                                    case 29:    //sec security level
                                    case 33:    //user has specific relation to user field
                                        if (ProcessFromDB.ProcessTypeStageFieldStatusId == 4 & ProcessFieldFromAPI.IntValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Required value is missing 2",
                                            }));
                                        }

                                        break;

                                    case 4:     //Date
                                    case 5:
                                    case 6:
                                    case 7:
                                    case 8:
                                    case 9:
                                        if (ProcessFromDB.ProcessTypeStageFieldStatusId == 4 & ProcessFieldFromAPI.DateTimeValue == null)
                                        {
                                            return(BadRequest(new
                                            {
                                                IsSuccess = false,
                                                Message = "Required value is missing 3",
                                            }));
                                        }

                                        break;

                                        //case 10: //button
                                        //case 11:
                                    }
                                }
                            }
                        }

                        foreach (var ProcessFieldFromAPI in ProcessesFromAPI.ProcessFields)
                        {
                            ProcessFields.Rows.Add(ProcessFieldFromAPI.ProcessTypeId, ProcessFieldFromAPI.ProcessTypeFieldId, ProcessFieldFromAPI.StringValue, ProcessFieldFromAPI.IntValue, ProcessFieldFromAPI.DateTimeValue);
                        }

                        //   SqlParameter Parameters = cmd.Parameters.AddWithValue("@FieldsTable", ProcessFields);
                        //    System.Data.SqlClient.SqlParameter[] Parameters =  {
                        //    new System.Data.SqlClient.SqlParameter("@User", CurrentUser.Id)
                        //    , new System.Data.SqlClient.SqlParameter("@ProcessTypeID", ProcessesFromAPI.ProcessTypeId)
                        //    , new System.Data.SqlClient.SqlParameter("@ProcessTypeStageID", ProcessesFromAPI.ProcessTypeStageId)
                        //    , new System.Data.SqlClient.SqlParameter("@FieldsTable", ProcessFields)
                        //};
                        await _processProvider.CreatePost("usp_CreateProcess @User, @ProcessTypeId, @ProcessTypeStageId, @FieldsTable", CurrentUser.Id, ProcessesFromAPI.ProcessTypeId, ProcessesFromAPI.ProcessTypeStageId, ProcessFields);

                        return(Ok());
                    }
                }
            }
            return(BadRequest(new
            {
                IsSuccess = false,
                Message = "No rights 1",
            }));
            //            return Ok();
        }