Exemplo n.º 1
0
        public ResultDTO SaveCluster(RuleClusterDTO ruleCluster)
        {
            ResultDTO sonuc       = new ResultDTO();
            var       resistivity = EditVisibleName(ruleCluster.ResistivityList);
            var       soil        = EditVisibleName(ruleCluster.SoilList);

            #region Database Operations

            try
            {
                _unitOfWork.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);

                #region Rule
                Kural rule = new Kural
                {
                    KuralAdi      = ruleCluster.RuleName,
                    AktifMi       = true,
                    EklenmeTarihi = DateTime.Now
                };
                _ruleService.BulkInsert(rule);
                #endregion

                #region RuleListText
                List <KuralListText> rules = new List <KuralListText>();
                foreach (var ruleListItem2 in ruleCluster.RuleList)
                {
                    string ruleText = GenerateRule(ruleListItem2);
                    rules.Add(new KuralListText {
                        KuralID = rule.KuralID, KuralText = ruleText
                    });
                }
                _ruleListTextService.BulkInsertRange(rules);
                #endregion

                #region Input Variable
                Degisken resistivityVariable = new Degisken
                {
                    KuralID            = rule.KuralID,
                    DegiskenTipID      = (byte)Enums.VariableType.Input,
                    DegiskenAdi        = "Özdirenç",
                    DegiskenGorunenAdi = "Ozdirenc"
                };
                _variableService.BulkInsert(resistivityVariable);
                var ozdirencItem = (from a in resistivity
                                    select new DegiskenItem()
                {
                    DegiskenID = resistivityVariable.DegiskenID,
                    DegiskenItemAdi = a.Name,
                    DegiskenItemGorunenAdi = a.VisibleName,
                    MinDeger = a.MinValue,
                    MaxDeger = a.MaxValue
                });
                _variableItemService.BulkInsertRange(ozdirencItem);
                #endregion

                #region Output Variable
                Degisken soilVariable = new Degisken
                {
                    KuralID            = rule.KuralID,
                    DegiskenTipID      = (byte)Enums.VariableType.Output,
                    DegiskenAdi        = "Toprak",
                    DegiskenGorunenAdi = "Toprak"
                };
                _variableService.BulkInsert(soilVariable);
                var soilItem = (from a in soil
                                select new DegiskenItem()
                {
                    DegiskenID = soilVariable.DegiskenID,
                    DegiskenItemAdi = a.Name,
                    DegiskenItemGorunenAdi = a.VisibleName,
                    MinDeger = a.MinValue,
                    MaxDeger = a.MaxValue
                });
                _variableItemService.BulkInsertRange(soilItem);
                #endregion

                #region RuleList
                List <KuralListItem> ruleListItem = new List <KuralListItem>();
                for (int i = 0; i < ruleCluster.RuleList.Count; i++)
                {
                    var ruleList = (new KuralList {
                        KuralID = rule.KuralID, SiraNo = (byte)(i + 1)
                    });
                    _ruleListService.BulkInsert(ruleList);

                    foreach (var item in ruleCluster.RuleList)
                    {
                        var InputVariableId = _variableItemService.Queryable().FirstOrDefault(d => d.Degisken.DegiskenTipID == (byte)Enums.VariableType.Input && d.DegiskenItemAdi == item.Rule.Resistivity).DegiskenItemID;
                        ruleListItem.Add(new KuralListItem {
                            KuralListID = ruleList.KuralListID, DegiskenItemID = InputVariableId
                        });

                        var OutputVariableId = _variableItemService.Queryable().FirstOrDefault(d => d.Degisken.DegiskenTipID == (byte)Enums.VariableType.Output && d.DegiskenItemAdi == item.Rule.Soil).DegiskenItemID;
                        ruleListItem.Add(new KuralListItem {
                            KuralListID = ruleList.KuralListID, DegiskenItemID = InputVariableId
                        });
                    }
                }
                _ruleListItemService.BulkInsertRange(ruleListItem);
                #endregion

                _unitOfWork.Commit();
                sonuc.Result  = true;
                sonuc.Message = "Save Successful For Rule Cluster.";
                sonuc.Object  = null;
                return(sonuc);
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback();
                sonuc.Result  = false;
                sonuc.Message = "An Error Occured While Saving Rule Cluster. Error: " + ex.Message;
                sonuc.Object  = null;
                return(sonuc);
            }

            #endregion
        }