/// <summary>
        /// Saves the load category.
        /// </summary>
        /// <param name="loadCategory">The load category.</param>
        /// <returns></returns>
        public static int SaveLoadCategory(LoadCategory loadCategory)
        {
            try
            {
                if (loadCategory.IsValid)
                {
                    // Save entity
                    loadCategory.Id = DataAccessProvider.Instance().SaveLoadCategory(loadCategory);
                }
                else
                {
                    // Entity is not valid
                    throw new InValidBusinessObjectException(loadCategory);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }

            // Done
            return(loadCategory.Id);
        }
Beispiel #2
0
        public IActionResult Add(AddLoadViewModel addLoadViewModel)
        {
            if (ModelState.IsValid)
            {
                LoadCategory newLoadCategory =
                    context.LoadCategories.Single(c => c.ID == addLoadViewModel.LoadCategoryID);

                Load newLoad = new Load
                {
                    Date         = addLoadViewModel.Date,
                    Reference    = addLoadViewModel.Reference,
                    Description  = addLoadViewModel.Description,
                    Owner        = addLoadViewModel.Owner,
                    Amount       = addLoadViewModel.Amount,
                    LoadCategory = newLoadCategory,
                };



                context.Loads.Add(newLoad);
                context.SaveChanges();

                return(Redirect("/Load"));
            }

            return(View(addLoadViewModel));
        }
 public void SaveLoadCategoryTestConstraint()
 {
     using (TransactionScope ts = new TransactionScope())
     {
         LoadCategory loadCategory = PopulateNewItem();
         SaveItem(loadCategory);
         SaveItem(loadCategory);
     }
 }
        /// <summary>
        /// Populates the new item.
        /// </summary>
        /// <returns></returns>
        internal LoadCategory PopulateNewItem()
        {
            LoadCategory loadCategory = new LoadCategory();

            loadCategory.Code        = "TEST";
            loadCategory.Description = "Test";
            loadCategory.UpdatedBy   = "TDC Team";
            return(loadCategory);
        }
 public void TestSaveLoadCategory()
 {
     using (TransactionScope scope = new TransactionScope())
     {
         LoadCategory loadCategory = PopulateNewItem();
         int          Id           = SaveItem(loadCategory);
         Assert.IsTrue(Id != -1);
     }
 }
Beispiel #6
0
        static void Main()
        {
            // PRACTICAL EXAMPLE: SETTING UP LOAD GROUPS
            // This example shows the core steps of creating load groups for a model.

            // This example was last updated 2022-04-06, using the ver. 21.1.0 FEM-Design API.


            // CREATING LOAD CASES
            LoadCase deadLoad1 = new LoadCase("Deadload1", LoadCaseType.DeadLoad, LoadCaseDuration.Permanent);
            LoadCase deadLoad2 = new LoadCase("Deadload2", LoadCaseType.DeadLoad, LoadCaseDuration.Permanent);
            LoadCase liveLoad1 = new LoadCase("Liveload1", LoadCaseType.Static, LoadCaseDuration.Permanent);
            LoadCase liveLoad2 = new LoadCase("Liveload2", LoadCaseType.Static, LoadCaseDuration.Permanent);

            List <LoadCase> loadCasesDeadLoads = new List <LoadCase>()
            {
                deadLoad1, deadLoad2
            };
            List <LoadCase> loadCaseLiveLoads = new List <LoadCase>()
            {
                liveLoad1, liveLoad2
            };


            // FETCHING LOAD CATEGORY DATABASE
            var          loadCategoryDatabase = LoadCategoryDatabase.GetDefault();
            LoadCategory loadCategory         = loadCategoryDatabase.LoadCategoryByName("A");


            // CREATING LOAD GROUPS
            var LG1 = new ModelGeneralLoadGroup(new LoadGroupPermanent(1, 1.35, 1, 1, loadCasesDeadLoads, ELoadGroupRelationship.Simultaneous, 0.89, "LG1"));
            var LG2 = new ModelGeneralLoadGroup(new LoadGroupTemporary(1.5, loadCategory.Psi0, loadCategory.Psi1, loadCategory.Psi2, true, loadCaseLiveLoads, ELoadGroupRelationship.Alternative, "LG2"));

            var loadGroups = new List <ModelGeneralLoadGroup>()
            {
                LG1, LG2
            };


            // CREATING AND OPENING NEW MODEL
            var model2 = new Model(Country.S, null, null, loadCasesDeadLoads.Concat(loadCaseLiveLoads).ToList(), null, loadGroups);

            string path = Path.GetFullPath("output/LoadGroups.struxml");

            if (!Directory.Exists("output"))
            {
                Directory.CreateDirectory("output");
            }

            model2.SerializeModel(path);
            var app = new Calculate.Application();

            app.OpenStruxml(path, true);
        }
        public ProductImportViewModel(CategoryService categoryService, ProductService productService)
        {
            LoadCategory = ReactiveCommand.CreateFromTask(categoryService.GetCategorySelectList);
            LoadCategory.ThrownExceptions.Subscribe(error => { });
            LoadCategory.ToPropertyEx(this, x => x.LoadCategoryResults, scheduler: RxApp.MainThreadScheduler);


            Save = ReactiveCommand.CreateFromTask(x => productService.Save(NewProduct));
            Save.ThrownExceptions.Subscribe(error => { });
            Save.Subscribe(x => { NewProduct = new NewProductViewModel(); });
        }
        public IActionResult Remove(int[] loadCategoryIds)
        {
            foreach (int loadCategoryId in loadCategoryIds)
            {
                LoadCategory theLoadCategory = context.LoadCategories.Single(c => c.ID == loadCategoryId);
                context.LoadCategories.Remove(theLoadCategory);
            }

            context.SaveChanges();

            return(Redirect("/LoadCategory"));
        }
 public void TestDeleteLoadCategory()
 {
     using (TransactionScope scope = new TransactionScope())
     {
         int id = SaveItem(PopulateNewItem());
         if (id != -1)
         {
             LoadCategory loadCategoryToDelete = new LoadCategory();
             loadCategoryToDelete.Id = id;
             Assert.IsTrue(DeleteItem(loadCategoryToDelete));
         }
     }
 }
        public void TestGetLoadCategory()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                LoadCategory loadCategory = PopulateNewItem();
                int          Id           = SaveItem(loadCategory);

                if (Id != -1)
                {
                    Assert.IsNotNull(GetItem(Id));
                }
            }
        }
Beispiel #11
0
        public IActionResult Category(int id)
        {
            if (id == 0)
            {
                Redirect("/Load");
            }

            LoadCategory theCategory = context.LoadCategories
                                       .Include(cat => cat.Loads)
                                       .Single(cat => cat.ID == id);

            ViewBag.Title = "Loads in Category" + theCategory.Name;
            return(View("Index", theCategory.Loads));
        }
        public void TestGetLoadCategories()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                LoadCategory loadCategory = PopulateNewItem();
                SaveItem(loadCategory);
                loadCategory.Id          = -1;
                loadCategory.Code        = "TWO";
                loadCategory.Description = "Second";
                SaveItem(loadCategory);

                List <LoadCategory> loadCategoryList = GetAllItems();
                Assert.IsTrue(loadCategoryList.Count != 0);
            }
        }
        public void TestUpdateLoadCategory()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                LoadCategory loadCategory = PopulateNewItem();
                loadCategory.Description = "Original";
                loadCategory.Id          = SaveItem(loadCategory);
                loadCategory             = GetItem(loadCategory.Id);
                //change a value
                loadCategory.Description = "Updated";

                SaveItem(loadCategory);
                loadCategory = GetItem(loadCategory.Id);
                Assert.IsTrue(loadCategory.Description == "Updated");
            }
        }
        /// <summary>
        /// Gets the load category.
        /// </summary>
        /// <param name="categoryCode">The category code.</param>
        /// <returns></returns>
        public static LoadCategory GetLoadCategory(string categoryCode)
        {
            LoadCategory loadCategory = null;

            try
            {
                loadCategory = CBO <LoadCategory> .FillObject(DataAccessProvider.Instance().GetLoadCategory(categoryCode));
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }
            return(loadCategory);
        }
        public IActionResult Add(AddLoadCategoryViewModel addLoadCategoryViewModel)
        {
            if (ModelState.IsValid)
            {
                LoadCategory newLoadCategory = new LoadCategory
                {
                    Name = addLoadCategoryViewModel.Name,
                };

                context.LoadCategories.Add(newLoadCategory);
                context.SaveChanges();

                return(Redirect("/LoadCategory"));
            }

            return(View(addLoadCategoryViewModel));
        }
Beispiel #16
0
        private List <LoadCombination> CreateLoadCombinations()
        {
            // Create load cases
            LoadCase        deadLoad1          = new LoadCase("Deadload1", LoadCaseType.DeadLoad, LoadCaseDuration.Permanent);
            LoadCase        deadLoad2          = new LoadCase("Deadload2", LoadCaseType.DeadLoad, LoadCaseDuration.Permanent);
            LoadCase        liveLoad1          = new LoadCase("Liveload1", LoadCaseType.Static, LoadCaseDuration.Permanent);
            LoadCase        liveLoad2          = new LoadCase("Liveload2", LoadCaseType.Static, LoadCaseDuration.Permanent);
            LoadCase        windLoad1          = new LoadCase("Windload1", LoadCaseType.Static, LoadCaseDuration.Permanent);
            LoadCase        windLoad2          = new LoadCase("Windload2", LoadCaseType.Static, LoadCaseDuration.Permanent);
            List <LoadCase> loadCasesDeadLoads = new List <LoadCase>()
            {
                deadLoad1, deadLoad2
            };
            List <LoadCase> loadCaseCategoryA = new List <LoadCase>()
            {
                liveLoad1, liveLoad2
            };
            List <LoadCase> loadCaseCategoryWind = new List <LoadCase>()
            {
                windLoad1, windLoad2
            };
            List <LoadCase> loadCases = loadCasesDeadLoads.Concat(loadCaseCategoryA).Concat(loadCaseCategoryWind).ToList();

            // Get the load categories that hold the coefficients
            var          loadCategoryDatabase = LoadCategoryDatabase.GetDefault();
            LoadCategory loadCategoryA        = loadCategoryDatabase.LoadCategoryByName("A");
            LoadCategory loadCategoryWind     = loadCategoryDatabase.LoadCategoryByName("Wind");

            // Create load groups
            var LGPermanent = new LoadGroupPermanent(1, 1.35, 1, 1, loadCasesDeadLoads, ELoadGroupRelationship.Entire, 0.89, "LGPermanent");
            var LGA         = new LoadGroupTemporary(1.5, loadCategoryA.Psi0, loadCategoryA.Psi1, loadCategoryA.Psi2, true, loadCaseCategoryA, ELoadGroupRelationship.Alternative, "LGCategoryA");
            var LGWind      = new LoadGroupTemporary(1.5, loadCategoryWind.Psi0, loadCategoryWind.Psi1, loadCategoryWind.Psi2, true, loadCaseCategoryWind, ELoadGroupRelationship.Alternative, "LGCategoryWind");

            var loadGroups = new List <LoadGroupBase>()
            {
                LGPermanent, LGA, LGWind
            };

            // Generate ULS and SLS Combinations
            LoadCombinationTable loadCombinationTable = new LoadCombinationTable();

            Program.CombineULS(loadGroups, loadCombinationTable);
            Program.CombineSLS(loadGroups, loadCombinationTable);
            return(loadCombinationTable.LoadCombinations);
        }
 //[ExpectedException(typeof (ConcurrencyException))]
 public void UpdateLoadCategoryConcurrencyTest()
 {
     using (TransactionScope ts = new TransactionScope())
     {
         LoadCategory loadCategory = PopulateNewItem();
         loadCategory.Id = SaveItem(loadCategory);
         //We didn't get the new checksum so when we save again an exception should be thrown
         try
         {
             SaveItem(loadCategory);
         }
         catch (DiscoveryException e)
         {
             Assert.IsInstanceOfType(typeof(ConcurrencyException), e.InnerException);
             throw e;
         }
     }
 }
        /// <summary>
        /// Deletes the load category.
        /// </summary>
        /// <param name="loadCategory">The load category.</param>
        /// <returns></returns>
        public static bool DeleteLoadCategory(LoadCategory loadCategory)
        {
            bool success = false;

            try
            {
                if (loadCategory != null)
                {
                    success = DataAccessProvider.Instance().DeleteLoadCategory(loadCategory.Id);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, "Business Logic"))
                {
                    throw;
                }
            }
            return(success);
        }
Beispiel #19
0
        static void Main()
        {
            // PRACTICAL EXAMPLE: COMBINING LOAD GROUPS
            // This example shows the steps for creating a complete set of load combination,
            // combining existing load groups. In addition to the main program, there are two
            // public functions at the bottom - CombineULS and CombineSLS.

            // This example was last updated 2022-04-06, using the ver. 21.1.0 FEM-Design API.


            // Create load cases
            LoadCase        deadLoad1          = new LoadCase("Deadload1", LoadCaseType.DeadLoad, LoadCaseDuration.Permanent);
            LoadCase        deadLoad2          = new LoadCase("Deadload2", LoadCaseType.DeadLoad, LoadCaseDuration.Permanent);
            LoadCase        liveLoad1          = new LoadCase("Liveload1", LoadCaseType.Static, LoadCaseDuration.Permanent);
            LoadCase        liveLoad2          = new LoadCase("Liveload2", LoadCaseType.Static, LoadCaseDuration.Permanent);
            LoadCase        windLoad1          = new LoadCase("Windload1", LoadCaseType.Static, LoadCaseDuration.Permanent);
            LoadCase        windLoad2          = new LoadCase("Windload2", LoadCaseType.Static, LoadCaseDuration.Permanent);
            List <LoadCase> loadCasesDeadLoads = new List <LoadCase>()
            {
                deadLoad1, deadLoad2
            };
            List <LoadCase> loadCaseCategoryA = new List <LoadCase>()
            {
                liveLoad1, liveLoad2
            };
            List <LoadCase> loadCaseCategoryWind = new List <LoadCase>()
            {
                windLoad1, windLoad2
            };
            List <LoadCase> loadCases = loadCasesDeadLoads.Concat(loadCaseCategoryA).Concat(loadCaseCategoryWind).ToList();


            // Get the load categories that hold the coefficients
            var          loadCategoryDatabase = LoadCategoryDatabase.GetDefault();
            LoadCategory loadCategoryA        = loadCategoryDatabase.LoadCategoryByName("A");
            LoadCategory loadCategoryWind     = loadCategoryDatabase.LoadCategoryByName("Wind");


            // Create load groups
            var LGPermanent = new LoadGroupPermanent(1, 1.35, 1, 1, loadCasesDeadLoads, ELoadGroupRelationship.Entire, 0.89, "LGPermanent");
            var LGA         = new LoadGroupTemporary(1.5, loadCategoryA.Psi0, loadCategoryA.Psi1, loadCategoryA.Psi2, true, loadCaseCategoryA, ELoadGroupRelationship.Alternative, "LGCategoryA");
            var LGWind      = new LoadGroupTemporary(1.5, loadCategoryWind.Psi0, loadCategoryWind.Psi1, loadCategoryWind.Psi2, true, loadCaseCategoryWind, ELoadGroupRelationship.Alternative, "LGCategoryWind");

            var loadGroups = new List <LoadGroupBase>()
            {
                LGPermanent, LGA, LGWind
            };


            // Wrap the load groups so that they can be added to the load group table
            var generalLoadGroups = new List <ModelGeneralLoadGroup>()
            {
                new ModelGeneralLoadGroup(LGPermanent), new ModelGeneralLoadGroup(LGA),
                new ModelGeneralLoadGroup(LGWind)
            };

            // Generate ULS and SLS Combinations
            List <LoadCombination> loadCombinations;
            LoadCombinationTable   loadCombinationTable = new LoadCombinationTable();

            CombineULS(loadGroups, loadCombinationTable);
            CombineSLS(loadGroups, loadCombinationTable);
            loadCombinations = loadCombinationTable.LoadCombinations;


            // Create model and open file in FEM design
            var model2 = new Model(Country.S, null, null, loadCases, loadCombinations, generalLoadGroups);

            string path = Path.GetFullPath("output/LoadGroupsAndCombinations.struxml");

            if (!Directory.Exists("output"))
            {
                Directory.CreateDirectory("output");
            }

            model2.SerializeModel(path);
            var app = new Calculate.Application();

            app.OpenStruxml(path, true);
        }
 /// <summary>
 /// Deletes the item.
 /// </summary>
 /// <param name="loadCategory">The load category.</param>
 /// <returns></returns>
 internal bool DeleteItem(LoadCategory loadCategory)
 {
     return(LoadCategoryController.DeleteLoadCategory(loadCategory));
 }
 /// <summary>
 /// Saves the item.
 /// </summary>
 /// <param name="loadCategory">The load category.</param>
 /// <returns></returns>
 internal int SaveItem(LoadCategory loadCategory)
 {
     return(LoadCategoryController.SaveLoadCategory(loadCategory));
 }