Exemplo n.º 1
0
        public async Task <IActionResult> Create2(SuContentCreate2GetModel FromForm)
        {
            var CurrentUser = await _userManager.GetUserAsync(User);

            var ProjectId = FromForm.Content.ProjectId == null ? 0 : FromForm.Content.ProjectId;

            SqlParameter[] parameters =
            {
                new SqlParameter("@ContentTypeId",     FromForm.Content.ContentTypeId),
                new SqlParameter("@ContentStatusId",   FromForm.Content.ContentStatusId),
                new SqlParameter("@LangaugeId",        FromForm.Content.LanguageId),
                new SqlParameter("@Title",             FromForm.Content.Title),
                new SqlParameter("@Description",       FromForm.Content.Description),
                new SqlParameter("@SecurityLevel",     FromForm.Content.SecurityLevel),
                new SqlParameter("@OrganizationId",    FromForm.Content.OrganizationId),
                new SqlParameter("@ProjectId",         ProjectId ?? 0),
                new SqlParameter("@CreatorId",         CurrentUser.Id),
                new SqlParameter("@ProcessTemplateId", FromForm.ProcessTemplateId),

                new SqlParameter
                {
                    ParameterName                                = "@new_identity",
                    SqlDbType                                    = SqlDbType.Int
                    ,                                  Direction = ParameterDirection.Output
                }
            };

            _context.Database.ExecuteSqlCommand("ContentCreate2Post @ContentTypeId" +
                                                ", @ContentStatusId" +
                                                ", @LangaugeId" +
                                                ", @Title" +
                                                ", @Description" +
                                                ", @SecurityLevel" +
                                                ", @OrganizationId" +
                                                ", @ProjectId" +
                                                ", @CreatorId" +
                                                ", @ProcessTemplateId" +
                                                ", @new_identity OUTPUT", parameters);

            if (FromForm.NoOfClassifications != null)
            {
                //
                foreach (var x in FromForm.SelectedValues)
                {
                    //                    SqlParameter[] parameters2 = new SqlParameter[2];
                    if (x.Value != 0)
                    {
                        SqlParameter[] parameters2 =
                        {
                            new SqlParameter("@ContentId",             parameters[9].Value),
                            new SqlParameter("@ClassificationValueId", x.Value)
                        };
                        _context.Database.ExecuteSqlCommand("ContentValueCreate @ContentId, @ClassificationValueId", parameters2);
                    }
                }
            }



            return(RedirectToRoute(new
            {
                controller = "Home",
                action = "Index2"
            }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create2(int Id)
        {
            var CurrentUser = await _userManager.GetUserAsync(User);

            var DefaultLanguageID = CurrentUser.DefaultLanguageId;

            var UICustomizationArray = new UICustomization(_context);

            ViewBag.Terms = await UICustomizationArray.UIArray(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), DefaultLanguageID);

            Menus a = new Menus(_context);

            ViewBag.menuItems = await a.TopMenu(DefaultLanguageID);


            SqlParameter[] parametersForAllowed =
            {
                new SqlParameter("@CurrentUser", CurrentUser.Id)
                ,                                new SqlParameter("@Id", Id)
            };
            var CheckIfAllowed = _context.ZdbInt.FromSql("ContentCreate2GetAllowed @CurrentUser, @Id", parametersForAllowed).First();

            if (CheckIfAllowed.intValue == 0)
            {
                return(RedirectToRoute(new
                {
                    controller = "Home",
                    action = "Index2"
                }));
            }

            var StatusList          = new List <SelectListItem>();
            var OrganizationList    = new List <SelectListItem>();
            var ProjectList         = new List <SelectListItem>();
            var SecurityLevelList   = new List <SelectListItem>();
            var LanguageList        = new List <SelectListItem>();
            int NoOfClassifications = _classification.GetAllClassifcations().Count();

            var parameterForProcess = new SqlParameter("@Id", Id);
            var ProcessTemplateId   = _context.ZdbInt2.FromSql("ContentCreate2ProcessTemplateIdGet  @Id", parameterForProcess).First();


            List <SelectListItem>[] ClassificationValueSets = new List <SelectListItem> [NoOfClassifications];

            SqlParameter[] parametersForClassifications =
            {
                new SqlParameter("@Id", Id)
                ,                       new SqlParameter("@CurrentUser", CurrentUser.Id)
            };
            var ClassificationIdsFromDb = _context.ZdbInt.FromSql("ContentCreate2GetClassifications  @Id, @CurrentUser", parametersForClassifications).ToList();


            //  DbSet<SuValueList>[] dbValueList = new DbSet<SuValueList>[NoOfClassifications];
            int y = 0;

            foreach (var ClassificationfromDb in ClassificationIdsFromDb)
            {
                List <SuValueList> ValuesFromDb = new List <SuValueList>();

                SqlParameter[] parameters =
                {
                    new SqlParameter("@LanguageId", CurrentUser.DefaultLanguageId)
                    ,                               new SqlParameter("@Id", ClassificationfromDb.intValue)
                };

                ValuesFromDb = _context.DbValueList.FromSql("ClassificationValueStructureValues  @LanguageId, @Id", parameters).ToList();
                ClassificationValueSets[y] = new List <SelectListItem>
                {
                    new SelectListItem

                    {
                        Text  = "-- no selection --",
                        Value = "0"
                    }
                };
                foreach (var ValueFromDb in ValuesFromDb)
                {
                    ClassificationValueSets[y].Add(new SelectListItem

                    {
                        Text  = ValueFromDb.Name,
                        Value = ValueFromDb.ClassificationValueId.ToString()
                    });
                }
                y++;
            }

            var ContentStatusFromDb = _context.ZDbStatusList.FromSql("ContentStatusList").ToList();


            foreach (var StatusFromDb in ContentStatusFromDb)
            {
                StatusList.Add(new SelectListItem
                {
                    Text  = StatusFromDb.Name,
                    Value = StatusFromDb.Id.ToString()
                });
            }

            var parameter = new SqlParameter("@LanguageId", CurrentUser.DefaultLanguageId);



            var OrganizationsFromDb = _context.ZdbOrganizationIndexGet.FromSql("OrgStructure @LanguageId", parameter).ToList();

            foreach (var OrganizationFromDb in OrganizationsFromDb)
            {
                OrganizationList.Add(new SelectListItem
                {
                    Text  = OrganizationFromDb.Name,
                    Value = OrganizationFromDb.Id.ToString()
                });
            }

            var ProjectsFromDb = _context.ZDbGetProjectStructure.FromSql("ProjStructure @LanguageId", parameter).ToList();

            ProjectList.Add(new SelectListItem {
                Value = "0", Text = "No project"
            });
            foreach (var ProjectFromDb in ProjectsFromDb)
            {
                ProjectList.Add(new SelectListItem
                {
                    Text  = ProjectFromDb.Name,
                    Value = ProjectFromDb.Id.ToString()
                });
            }


            var SecurityLevelsFromDb = _context.ZDbSecurityLevelList.FromSql("SecurityLevelSelectAll").ToList();

            foreach (var SecurityLevelFromDb in SecurityLevelsFromDb)
            {
                SecurityLevelList.Add(new SelectListItem
                {
                    Text  = SecurityLevelFromDb.Name,
                    Value = SecurityLevelFromDb.Id.ToString()
                });
            }

            var LanguagesFromDb = _context.ZDbLanguageList.FromSql("LanguageSelectAll").ToList();

            foreach (var LanguageFromDb in LanguagesFromDb)
            {
                LanguageList.Add(new SelectListItem
                {
                    Text  = LanguageFromDb.Name,
                    Value = LanguageFromDb.Id.ToString()
                });
            }


            SuContentModel content = new SuContentModel
            {
                LanguageId = CurrentUser.DefaultLanguageId
                ,
                ContentTypeId = Id
            };

            int?[] SelectedValues = new int?[NoOfClassifications];
            SuContentCreate2GetModel ContentWithDropDowns = new SuContentCreate2GetModel
            {
                Content = content
                ,
                ProcessTemplateId = ProcessTemplateId.intValue
                ,
                ContentStatus = StatusList
                ,
                SecurityLevel = SecurityLevelList
                ,
                Langauge = LanguageList
                ,
                Organization = OrganizationList
                ,
                Project = ProjectList
                ,
                Values = ClassificationValueSets
                ,
                NoOfClassifications = NoOfClassifications
                ,
                SelectedValues = SelectedValues
            };

            ViewBag.tools = new[] {
                "Bold", "Italic", "Underline", "StrikeThrough",
                "FontName", "FontSize", "FontColor", "BackgroundColor",
                "LowerCase", "UpperCase", "|",
                "Formats", "Alignments", "OrderedList", "UnorderedList",
                "Outdent", "Indent", "|",
                "CreateLink", "Image", "CreateTable", "|", "ClearFormat", "Print",
                "SourceCode", "FullScreen", "|", "Undo", "Redo"
            };

            return(View(ContentWithDropDowns));
        }