Exemple #1
0
 public FormTaxonomy(TaxonomyViewModel taxonomyViewModel)
 {
     Id       = taxonomyViewModel.Id;
     Name     = taxonomyViewModel.Name;
     Title    = taxonomyViewModel.Title;
     ParentId = taxonomyViewModel.ParentId;
 }
        /// <summary>
        /// Creates the view model.
        /// </summary>
        /// <returns></returns>
        public override TaxonomyViewModel CreateViewModel()
        {
            var viewModel = new TaxonomyViewModel
            {
                ShowItemCount = this.ShowItemCount,
                CssClass      = this.CssClass
            };

            if (this.ContentId != Guid.Empty)
            {
                viewModel.Taxa = this.GetTaxaByContentItem();
                return(viewModel);
            }

            switch (this.TaxaToDisplay)
            {
            case FlatTaxaToDisplay.Selected:
                viewModel.Taxa = this.GetSpecificTaxa <FlatTaxon>();
                break;

            case FlatTaxaToDisplay.UsedByContentType:
                viewModel.Taxa = this.GetTaxaByContentType();
                break;

            default:
                viewModel.Taxa = this.GetAllTaxa <FlatTaxon>();
                break;
            }

            return(viewModel);
        }
        private ColumnValidationResult ValidateTaxonomyFields(TaxonomyViewModel report)
        {
            ColumnValidationResult result = new ColumnValidationResult();

            result.EntityId = report.TaxonomyId;

            result = ValidationField("TaxonomyId", report.TaxonomyId, "שדה קוד טקסונומיה הינו שדה חובה", result);

            result = ValidationField("Description", report.Description, "שדה תיאור טקסונומיה הינו שדה חובה", result);

            result = ValidationDateField("TaxonomyDate", report.TaxonomyDate, "שדה תאריך טקסונומיה הינו שדה חובה", result);

            result = ValidationField("EntityIdentifier", report.EntityIdentifier, "שדה מזהה ישות הינו שדה חובה", result);

            result = ValidationField("Currency", report.Currency, "שדה מטבע הינו שדה חובה", result);

            result = ValidationField("Decimals", report.Decimals, "שדה Decimals הינו שדה חובה", result);

            result = ValidationField("EntitySchema", report.EntitySchema, "שדה סכמת ישות הינו שדה חובה", result);

            result = ValidationDateField("TaxonomyCreationDate", report.TaxonomyCreationDate, "שדה תאריך יצירה הינו שדה חובה", result);

            result = ValidationField("TnProcessorId", report.TnProcessorId, "שדה TnProcessorId הינו שדה חובה", result);

            return(result);
        }
        /// <summary>
        /// Creates the view model.
        /// </summary>
        /// <returns></returns>
        public override TaxonomyViewModel CreateViewModel()
        {
            var viewModel = new TaxonomyViewModel
            {
                ShowItemCount = this.ShowItemCount,
                CssClass = this.CssClass
            };

            if (this.ContentId != Guid.Empty)
            {
                viewModel.Taxa = this.GetTaxaByContentItem();
                return viewModel;
            }

            switch (this.TaxaToDisplay)
            {
                case FlatTaxaToDisplay.Selected:
                    viewModel.Taxa = this.GetSpecificTaxa<FlatTaxon>();
                    break;

                case FlatTaxaToDisplay.UsedByContentType:
                    viewModel.Taxa = this.GetTaxaByContentType();
                    break;

                default:
                    viewModel.Taxa = this.GetAllTaxa<FlatTaxon>();
                    break;

            }

            return viewModel;
        }
 public void Update(TaxonomyViewModel model)
 {
     CheckADObjectExists(model);
     using (FalconOrchestratorDB db = new FalconOrchestratorDB())
     {
         Taxonomy rule = db.Taxonomies.Find(model.TaxonomyId);
         rule.Description = model.Description;
         db.SaveChanges();
     }
 }
 private void CheckADObjectExists(TaxonomyViewModel model)
 {
     if (model.TypeId == 3 || model.TypeId == 4)
     {
         AppConfiguration config = new AppConfiguration(System.Configuration.ConfigurationManager.AppSettings["CryptoKey"]);
         LdapUtil         ldap   = new LdapUtil(config.LDAP_SERVER, config.LDAP_USERNAME, config.LDAP_PASSWORD);
         Boolean          exists = ldap.CheckIfDNExists(model.Value);
         if (!exists)
         {
             throw new NotSupportedException(model.Value + " does not exist in Active Directory database");
         }
     }
 }
Exemple #7
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            FalconOrchestratorDB db    = new FalconOrchestratorDB();
            TaxonomyViewModel    model = repo.Get(id);

            ViewBag.TypeId = new SelectList(db.TaxonomyTypes, "TaxTypeId", "Type", model.TypeId);
            return(View(model));
        }
Exemple #8
0
        public TaxonomyViewModel TaxonomyToViewModel(Taxonomy taxonomy)
        {
            var details = _taxEntityHelper.GetDetails(taxonomy).ToList();

            var result = new TaxonomyViewModel
            {
                Id       = taxonomy.Id,
                Name     = taxonomy.Name,
                ParentId = taxonomy.ParentId,
                Title    = details.First(o => o.Field == "title").Value
            };

            return(result);
        }
        /// <summary>
        /// This is called when this view becomes the "active" view
        /// </summary>
        protected override void OnActivate()
        {
            if (IsBevShowing)
            {
                BirdsEyeViewModel.SetActiveViewModel(this);
            }
            if (TaxonomyViewModel != null)
            {
                TaxonomyViewModel.SetActiveViewModel(this);
            }

            // Replace any open taxonomy view with our new data
            SendMessage(AlignmentViewMessages.SwitchAlignmentView, this);
            base.OnActivate();
        }
        public async Task <IEnumerable <dynamic> > SaveOrUpdate(TaxonomyViewModel tvm)
        {
            string sql = "dbo.EAppSaveTaxonomy";

            using (var conn = util.MasterCon())
            {
                try
                {
                    return(await(conn.QueryAsync <dynamic>(sql, new
                    {
                        tvm.TaxonomyId,
                        tvm.TaxonomyCode,
                        tvm.SectorId,
                        tvm.SegmentId,
                        tvm.IndustryId,
                        tvm.AssetTypeId,
                        tvm.FailureModeId,
                        tvm.FailureCauseId,
                        tvm.MTTR,
                        tvm.MTTROld,
                        tvm.MTBF,
                        tvm.MTBFOld,
                        tvm.Active,
                        tvm.UserId,
                        tvm.AssetCategoryId,
                        tvm.AssetClassId,
                        tvm.AssetSequenceId,
                        tvm.AssetClassTypeCode,
                        tvm.TaxonomyType
                    }, commandType: CommandType.StoredProcedure)));
                }
                catch (SqlException sqlException)
                {
                    if (sqlException.Number == 2601 || sqlException.Number == 2627)
                    {
                        throw new CustomException("Duplicate", "Combination of Industry, Asset Type, Failure Mode Type & Failure Cause Type already Exists.", "Error", true, sqlException);
                    }
                    else
                    {
                        throw new CustomException("Due to some Technical Reason, Unable to Save or Update", "Error", true, sqlException);
                    }
                }
                catch (Exception ex)
                {
                    throw new CustomException("Unable to Save Or Update, Please Contact Support!!!", "Error", true, ex);
                }
            }
        }
 public TaxonomyViewModel Get(int?id)
 {
     using (FalconOrchestratorDB db = new FalconOrchestratorDB())
     {
         Taxonomy          rule  = db.Taxonomies.Find(id);
         TaxonomyViewModel model = new TaxonomyViewModel();
         model.TaxonomyId  = rule.TaxonomyId;
         model.Creator     = rule.Creator;
         model.Critical    = rule.Critical;
         model.Description = rule.Description;
         model.Type        = rule.TaxonomyType.Type;
         model.TypeId      = rule.TaxTypeId;
         model.Value       = rule.Value;
         return(model);
     }
 }
Exemple #12
0
 public async Task <IActionResult> Search([FromBody] TaxonomyViewModel tvm)
 {
     try
     {
         return(Ok(await taxonomyRepo.GetTaxonomyByParams(tvm)));
     }
     catch (CustomException cex)
     {
         var responseObj = new EmaintenanceMessage(cex.Message, cex.Type, cex.IsException, cex.Exception?.ToString());
         return(StatusCode(StatusCodes.Status500InternalServerError, responseObj));
     }
     catch (Exception ex)
     {
         return(Ok(new EmaintenanceMessage(ex.Message)));
     }
 }
 public void Create(TaxonomyViewModel model)
 {
     CheckADObjectExists(model);
     using (FalconOrchestratorDB db = new FalconOrchestratorDB())
     {
         Taxonomy rule = new Taxonomy();
         rule.Value       = model.Value;
         rule.Timestamp   = DateTime.UtcNow;
         rule.TaxTypeId   = model.TypeId;
         rule.Description = model.Description;
         rule.Critical    = model.Critical;
         rule.Creator     = model.Creator;
         db.Taxonomies.Add(rule);
         db.SaveChanges();
         ApplyRetoractively(db, model, rule.TaxonomyId);
     }
 }
        public async Task <IEnumerable <dynamic> > GetTaxonomyByParams(TaxonomyViewModel tvm)
        {
            string sql = "dbo.EAppListTaxonomy";

            using (var conn = util.MasterCon())
            {
                try
                {
                    return(await(conn.QueryAsync <dynamic>(sql, new
                                                           { tvm.LanguageId, tvm.SectorId, tvm.SegmentId, tvm.IndustryId, tvm.AssetTypeId, tvm.FailureModeId, tvm.Status, tvm.AssetCategoryId, tvm.AssetClassId, tvm.AssetSequenceId },
                                                           commandType: CommandType.StoredProcedure)));
                }
                catch (Exception ex)
                {
                    throw new CustomException("Unable to Load Data, Please Contact Support!!!", "Error", true, ex);
                }
            }
        }
Exemple #15
0
 public async Task <IActionResult> Create([FromBody] TaxonomyViewModel tvm)
 {
     try
     {
         CurrentUser cUser = new CurrentUser(HttpContext, _configuration);
         tvm.UserId     = cUser.UserId;
         tvm.TaxonomyId = 0;
         tvm.Active     = "Y";
         return(Ok(await taxonomyRepo.SaveOrUpdate(tvm)));
     }
     catch (CustomException cex)
     {
         var returnObj = new EmaintenanceMessage(cex.Message, cex.Type, cex.IsException, cex.Exception?.ToString());
         return(StatusCode(StatusCodes.Status500InternalServerError, returnObj));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, new EmaintenanceMessage(ex.Message)));
     }
 }
        /// <summary>
        /// Creates the view model.
        /// </summary>
        /// <returns></returns>
        public override TaxonomyViewModel CreateViewModel()
        {
            var viewModel = new TaxonomyViewModel();

            viewModel.ShowItemCount = this.ShowItemCount;
            viewModel.CssClass      = this.CssClass;

            if (this.ContentId != Guid.Empty)
            {
                viewModel.Taxa = this.GetTaxaByContentItem();
                return(viewModel);
            }

            switch (this.TaxaToDisplay)
            {
            case HierarchicalTaxaToDisplay.All:
                viewModel.Taxa = this.GetAllTaxa <HierarchicalTaxon>();
                break;

            case HierarchicalTaxaToDisplay.TopLevel:
                viewModel.Taxa = this.GetTopLevelTaxa();
                break;

            case HierarchicalTaxaToDisplay.UnderParticularTaxon:
                viewModel.Taxa = this.GetTaxaByParent();
                break;

            case HierarchicalTaxaToDisplay.Selected:
                viewModel.Taxa = this.GetSpecificTaxa <HierarchicalTaxon>();
                break;

            case HierarchicalTaxaToDisplay.UsedByContentType:
                viewModel.Taxa = this.GetTaxaByContentType();
                break;

            default:
                viewModel.Taxa = this.GetTopLevelTaxa();
                break;
            }
            return(viewModel);
        }
Exemple #17
0
        public ActionResult Edit(TaxonomyViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    repo.Update(model);
                    return(RedirectToAction("Index"));
                }

                catch (Exception e)
                {
                    ModelState.AddModelError(String.Empty, e.Message);
                }
            }

            FalconOrchestratorDB db = new FalconOrchestratorDB();

            ViewBag.TypeId = new SelectList(db.TaxonomyTypes, "TaxTypeId", "Type", model.Type);
            return(View(model));
        }
        public List <TaxonomyViewModel> GetList()
        {
            List <TaxonomyViewModel> result = new List <TaxonomyViewModel>();

            using (FalconOrchestratorDB db = new FalconOrchestratorDB())
            {
                foreach (Taxonomy line in db.Taxonomies.ToList())
                {
                    TaxonomyViewModel model = new TaxonomyViewModel();
                    model.Creator     = line.Creator;
                    model.Critical    = line.Critical;
                    model.Description = line.Description;
                    model.TaxonomyId  = line.TaxonomyId;
                    model.Timestamp   = line.Timestamp.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                    model.Type        = line.TaxonomyType.Type;
                    model.TypeId      = line.TaxTypeId;
                    model.Value       = line.Value;
                    result.Add(model);
                }
            }
            return(result);
        }
        private void ApplyRetoractively(FalconOrchestratorDB db, TaxonomyViewModel model, int taxonomyId)
        {
            List <Detection> detections = db.Detections.Include("Account").Include("DetectionDevice").ToList();

            switch (model.TypeId)
            {
            case 1:
                detections = detections.Where(x => Regex.IsMatch(x.Account.AccountName, Regex.Replace(model.Value, @"\\", @"\\"))).ToList();
                break;

            case 2:
                detections = detections.Where(x => Regex.IsMatch(x.DetectionDevice.Device.Hostname, Regex.Replace(model.Value, @"\\", @"\\"))).ToList();
                break;

            case 3:
                detections = detections.Where(x => x.Account.OrganizationalUnit != null && x.Account.OrganizationalUnit.Equals(Regex.Replace(model.Value, @"\\", @"\\"))).ToList();
                break;

            case 4:
                var accountGroups = db.AccountGroups.Where(x => x.Group.Name == Regex.Replace(model.Value, @"\\", @"\\")).ToList();
                var accountIds    = accountGroups.Select(x => x.AccountId).ToList();
                detections = db.Detections.Where(x => accountIds.Contains(x.AccountId)).ToList();
                break;
            }

            foreach (Detection line in detections)
            {
                DetectionTaxonomy dt = new DetectionTaxonomy();
                dt.DetectionId = line.DetectionId;
                dt.TaxonomyId  = taxonomyId;
                db.DetectionTaxonomies.Add(dt);

                if (model.Critical)
                {
                    line.CustomSeverityId = 5;
                }
            }
            db.SaveChanges();
        }
        /// <summary>
        /// Creates the view model.
        /// </summary>
        /// <returns></returns>
        public override TaxonomyViewModel CreateViewModel()
        {
            var viewModel = new TaxonomyViewModel();
            viewModel.ShowItemCount = this.ShowItemCount;
            viewModel.CssClass = this.CssClass;

            if (this.ContentId != Guid.Empty)
            {
                viewModel.Taxa = this.GetTaxaByContentItem();
                return viewModel;
            }

            switch (this.TaxaToDisplay)
            {
                case HierarchicalTaxaToDisplay.All:
                    viewModel.Taxa = this.GetAllTaxa<HierarchicalTaxon>();
                    break;
                case HierarchicalTaxaToDisplay.TopLevel:
                    viewModel.Taxa = this.GetTopLevelTaxa();
                    break;
                case HierarchicalTaxaToDisplay.UnderParticularTaxon:
                    viewModel.Taxa = this.GetTaxaByParent();
                    break;
                case HierarchicalTaxaToDisplay.Selected:
                    viewModel.Taxa = this.GetSpecificTaxa<HierarchicalTaxon>();
                    break;
                case HierarchicalTaxaToDisplay.UsedByContentType:
                    viewModel.Taxa = this.GetTaxaByContentType();
                    break;
                default:
                    viewModel.Taxa = this.GetTopLevelTaxa();
                    break;
            }
            return viewModel;
        }
Exemple #21
0
 /// <summary>
 /// The update.
 /// </summary>
 /// <param name="model">
 /// The model.
 /// </param>
 public void Update(TaxonomyViewModel model)
 {
     this.taxonomyWrapper.Update(this.taxonomyMapper.Reverse(model), true);
 }
Exemple #22
0
 /// <summary>
 /// The create.
 /// </summary>
 /// <param name="model">
 /// The model.
 /// </param>
 /// <returns>
 /// The <see cref="int"/>.
 /// </returns>
 public int Create(TaxonomyViewModel model)
 {
     return(this.taxonomyWrapper.Create(this.taxonomyMapper.Reverse(model), true).TaxonomyId);
 }
        public async Task BuildNavigationAsync(MenuItem menuItem, NavigationBuilder builder, IEnumerable <IAdminNodeNavigationBuilder> treeNodeBuilders)
        {
            var node = menuItem as TaxonomyTermsAdminNode;

            if ((node == null) || (!node.Enabled))
            {
                return;
            }

            var taxonomy = await _contentManager.GetAsync(node.TaxonomyContentItemId, VersionOptions.Latest);

            if (taxonomy == null)
            {
                return;
            }

            //TODO this can move to a handler
            var taxonomyRootRouteValues = await _contentManager.PopulateAspectAsync <ContentItemMetadata>(taxonomy);

            var taxonomyRouteValues = new RouteValueDictionary
            {
                { "Area", "OrchardCore.Contents" },
                { "Controller", "Admin" },
                { "Action", "Display" },
                { "ContentItemId", taxonomy.ContentItemId }
            };

            var homeRoute       = (await _siteService.GetSiteSettingsAsync()).HomeRoute;
            var templateContext = new TemplateContext();

            templateContext.SetValue("ContentItem", taxonomy);

            var model = new TaxonomyViewModel
            {
                ContentItem = taxonomy
            };

            var taxonomyDisplayText = await _liquidTemplateManager.RenderAsync(node.TaxonomyDisplayPattern, _htmlEncoder, model,
                                                                               scope => scope.SetValue("ContentItem", model.ContentItem));

            //var taxonomyDisplayText = await _liquidTemplateManager.RenderAsync(node.TaxonomyDisplayPattern, NullEncoder.Default, templateContext);

            var termEntries = new List <TermMenuEntry>();

            PopulateTermEntries(termEntries, taxonomy.As <TaxonomyPart>().Terms, 0);

            await builder.AddAsync(new LocalizedString(taxonomyDisplayText, taxonomyDisplayText), async taxonomyRoot =>
            {
                //TODO this can route direct to taxonomy
                //var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(homeRouteContentItem.ContentType);
                taxonomyRoot.Action(taxonomyRootRouteValues.EditorRouteValues["Action"] as string, taxonomyRootRouteValues.EditorRouteValues["Controller"] as string, taxonomyRootRouteValues.EditorRouteValues);
                taxonomyRoot.Resource(taxonomy);
                taxonomyRoot.Priority(node.Priority);
                taxonomyRoot.Position(node.Position);
                taxonomyRoot.LocalNav();
                AddPrefixToClasses(node.IconForTree).ToList().ForEach(c => taxonomyRoot.AddClass(c));

                //taxonomyRoot.Permission(ContentTypePermissions.CreateDynamicPermission(
                //    ContentTypePermissions.PermissionTemplates[global::OrchardCore.Contents.Permissions.EditContent.Name], contentTypeDefinition));
                await BuildMenuLevels(taxonomyRoot, termEntries, 0, taxonomyRouteValues);
            });
        }
        public ActionResult AddTaxonomies([DataSourceRequest] DataSourceRequest request, TaxonomyViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                using (var repository = GetRepository())
                {
                    if (!IsTaxonomyUniqueId(model.TaxonomyId))
                    {
                        return(new JsonHttpStatusResult(new { Message = UserMessages.TAXSONOMY_IS_NOT_UNIQ_ID }, HttpStatusCode.InternalServerError));
                    }

                    var result = ValidateTaxonomyFields(model);

                    if (result.ValidationMessages.Count > 0)
                    {
                        return(new JsonHttpStatusResult(new { Message = result.ValidationMessages }, HttpStatusCode.InternalServerError));
                    }

                    var entity = new TaxonomyModel()
                    {
                        Currency             = model.Currency,
                        DecimalDecimals      = model.DecimalDecimals,
                        Decimals             = model.Decimals,
                        Description          = model.Description,
                        EntityIdentifier     = model.EntityIdentifier,
                        EntitySchema         = model.EntitySchema,
                        IntegerDecimals      = model.IntegerDecimals,
                        MonetaryDecimals     = model.MonetaryDecimals,
                        PureDecimals         = model.PureDecimals,
                        SharesDecimals       = model.SharesDecimals,
                        TaxonomyCreationDate = model.TaxonomyCreationDate,
                        TaxonomyDate         = model.TaxonomyDate,
                        TaxonomyId           = model.TaxonomyId,
                        TnProcessorId        = model.TnProcessorId,
                        TnRevisionId         = model.TnRevisionId
                    };

                    try
                    {
                        repository.TaxonomyRepository.Add(entity);
                        repository.Commit();
                    }
                    catch (Exception e)
                    {
                        GetLogger().LogException(e, string.Format("InsertTaxonomies({0})", model.TaxonomyId));

                        return(new JsonHttpStatusResult(new { Message = UserMessages.UNKNOWN_ERROR }, HttpStatusCode.InternalServerError));
                    }
                }
            }
            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }
        public ActionResult DeleteTaxonomies([DataSourceRequest] DataSourceRequest request, TaxonomyViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                if (string.IsNullOrWhiteSpace(model.TaxonomyId))
                {
                    return(new JsonHttpStatusResult(new { Message = UserMessages.TAXONOMYID_ERROR }, HttpStatusCode.InternalServerError));
                }

                using (var repository = GetRepository())
                {
                    var entity = repository.TaxonomyRepository
                                 .GetTaxonomyById(model.TaxonomyId);

                    if (entity == null)
                    {
                        return(new JsonHttpStatusResult(new { Message = UserMessages.ROW_NOT_FOUND_ERROR }, HttpStatusCode.InternalServerError));
                    }

                    try
                    {
                        repository.TaxonomyRepository.Remove(entity);
                        repository.Commit();
                    }
                    catch (Exception e)
                    {
                        GetLogger().LogException(e, string.Format("DeleteTaxonomy({0})", model.TaxonomyId));

                        return(new JsonHttpStatusResult(new { Message = UserMessages.UNKNOWN_ERROR }, HttpStatusCode.InternalServerError));
                    }
                }
            }
            return(Json(new[] { model }.ToDataSourceResult(request, ModelState)));
        }