Beispiel #1
0
        private void InitEcoFirstStage(SIN sin)
        {
            sin.InGame        = true;
            sin.OldMetaTypeId = null;
            sin.OldInsurance  = null;

            var wallet = CreateOrUpdateWallet(WalletTypes.Character, sin.WalletId ?? 0, 0);

            sin.Wallet = wallet;
            var scoring = Get <Scoring>(s => s.Id == sin.ScoringId);

            if (scoring == null)
            {
                scoring     = new Scoring();
                sin.Scoring = scoring;
                Add(scoring);
            }
            scoring.StartFactor      = 1;
            scoring.CurrentFix       = 0.5m;
            scoring.CurerentRelative = 0.5m;
            SaveContext();
            var categories = GetList <ScoringCategory>(c => c.CategoryType > 0);

            foreach (var category in categories)
            {
                var current = Get <CurrentCategory>(c => c.CategoryId == category.Id && c.ScoringId == sin.ScoringId);
                if (current != null)
                {
                    var factors = GetList <CurrentFactor>(c => c.CurrentCategoryId == current.Id);
                    RemoveRange(factors);
                    Remove(current);
                }
                current = new CurrentCategory
                {
                    CategoryId = category.Id,
                    ScoringId  = sin.ScoringId ?? 0,
                    Value      = sin.Scoring.StartFactor ?? 1
                };
                Add(current);
            }
            SaveContext();
            var transfers = GetList <Transfer>(t => t.WalletFromId == sin.WalletId || t.WalletToId == sin.WalletId);

            RemoveRange(transfers);
            SaveContext();
            var rentas = GetList <Renta>(r => r.SinId == sin.Id);

            RemoveRange(rentas);
            sin.EVersion = "2";
            SaveContext();
        }
        public CateroryAddOrUpdateViewModel(Action reLoadListCat, Action closeDialog, CategoryModel category = null)
        {
            if (category == null) // Add new
            {
                CurrentCategory = new CategoryModel();
            }
            else  // Edit
            {
                CurrentCategory = category.Clone();
                _isEdit         = true;
            }


            MaxLengthName     = CurrentCategory.GetAttributeFrom <MaxLengthAttribute>(nameof(CurrentCategory.Name)).Length;
            ReLoadList        = reLoadListCat;
            CloseDialogParent = closeDialog;
        }
Beispiel #3
0
        public CurrentScoringCategoryDto(CurrentCategory currentCategory, decimal currentSum, decimal currentResult) : base(currentCategory.Category)
        {
            var k = currentResult / (currentSum != 0 ? currentSum : 1);

            Value = Math.Round((currentCategory?.Value ?? 0) * k, 2);
        }
Beispiel #4
0
        private Task RaiseScoringEvent(int scoringId, int factorId, Func <BillingContext, decimal> action)
        {
            return(Task.Run(() =>
            {
                try
                {
                    using (var context = new BillingContext(true))
                    {
                        using (var dbContextTransaction = context.Database.BeginTransaction())
                        {
                            var connection = context.Database.GetDbConnection();
                            var id = connection.QueryFirstOrDefault <int>($"SELECT id FROM scoring  WHERE id = {scoringId} FOR UPDATE;");//block scoring for updates
                            var start = DateTime.Now;
                            var lifestyle = action(context);
                            var factor = context.Set <ScoringFactor>().AsNoTracking().FirstOrDefault(f => f.Id == factorId);
                            var category = context.Set <ScoringCategory>().AsNoTracking().FirstOrDefault(f => f.Id == factor.CategoryId);
                            var scoring = context.Set <Scoring>().AsTracking().FirstOrDefault(s => s.Id == scoringId);
                            var systemsettings = IocContainer.Get <ISettingsManager>();
                            var oldScoring = scoring.CurerentRelative + scoring.CurrentFix;
                            var curCategory = context.Set <CurrentCategory>().Include(f => f.Category)
                                              .FirstOrDefault(c => c.ScoringId == scoringId && c.CategoryId == factor.CategoryId);
                            if (curCategory == null)
                            {
                                curCategory = new CurrentCategory
                                {
                                    ScoringId = scoringId,
                                    CategoryId = factor.CategoryId,
                                    Category = category,
                                    Value = 1
                                };
                                Add(curCategory, context);
                            }
                            var curFactor = context.Set <CurrentFactor>()
                                            .FirstOrDefault(s => s.CurrentCategoryId == curCategory.Id && s.ScoringFactorId == factorId);
                            if (curFactor == null)
                            {
                                curFactor = new CurrentFactor
                                {
                                    ScoringFactorId = factorId,
                                    CurrentCategoryId = curCategory.Id,
                                    Value = scoring.StartFactor ?? 1
                                };
                                Add(curFactor, context);
                            }
                            var oldFactorValue = curFactor.Value;

                            var newValue = CalculateFactor((double)lifestyle, (double)curFactor.Value);
                            curFactor.Value = newValue;

                            Add(curFactor, context);
                            var curFactors = context.Set <CurrentFactor>().AsNoTracking().Include(f => f.ScoringFactor)
                                             .Where(f => f.CurrentCategoryId == curCategory.Id).ToList();

                            var allCates = context.Set <CurrentCategory>()
                                           .Where(c => c.ScoringId == scoringId && c.Category.CategoryType == category.CategoryType && c.CurrentFactors.Count > 0).ToList();
                            var factorsCount = curFactors.Count;
                            if (factorsCount == 0)
                            {
                                factorsCount = 1;
                            }
                            var oldCatValue = curCategory.Value;
                            var curCatCount = allCates.Count;
                            var k = (decimal)Math.Pow((curCatCount > 0 ? curCatCount : 2) * 2, -1);
                            var averFactors = curFactors.Sum(f => f.Value) / factorsCount;
                            var catWeight = curCategory?.Category?.Weight;
                            curCategory.Value = (decimal)Math.Pow((double)averFactors, (double)GetCatWeight(catWeight ?? 0));
                            Add(curCategory, context);
                            var newCatValue = curCategory.Value;
                            if (category.CategoryType == (int)ScoringCategoryType.Fix)
                            {
                                scoring.CurrentFix = allCates.Sum(c => c.Value) * k;
                            }
                            else if (category.CategoryType == (int)ScoringCategoryType.Relative)
                            {
                                scoring.CurerentRelative = allCates.Sum(c => c.Value) * k;
                            }
                            Add(scoring, context);
                            var end = DateTime.Now;
                            var scoringEvent = new ScoringEvent
                            {
                                FinishTime = end,
                                StartTime = start,
                                CurrentFactor = curFactor,
                                OldFactorValue = oldFactorValue,
                                NewFactorValue = newValue,
                                OldCategoryValue = oldCatValue,
                                NewCategoryValue = newCatValue,
                                OldScoring = oldScoring,
                                NewScoring = scoring.CurerentRelative + scoring.CurrentFix,
                                SaveK = k,
                                AverFactors = averFactors
                            };
                            Add(scoringEvent, context);
                            dbContextTransaction.Commit();
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e.ToString());
                }
            }));
        }
Beispiel #5
0
        public string CacheKey(int PageNumber, int PageCount)
        {
            var category = (CurrentCategory.HasValue ? CurrentCategory.ToString() : string.Empty) + '|' + string.Join(",", _categoryIds);

            return($"{PageNumber}|{PageCount}|{Harmony.ToString()}|{Sort}|{category}|{string.Join(",", _tagIds)}");
        }