예제 #1
0
        public ShopDto CreateOrUpdateShopWallet(int shopId = 0, decimal balance = 0, string name = "default shop", int lifestyle = 1, int ownerId = 0, List <int> specialisations = null, string comment = "", string location = "")
        {
            ShopWallet shop = null;

            if (shopId == 0)
            {
                var newWallet = CreateOrUpdateWallet(WalletTypes.Shop);
                shop = new ShopWallet
                {
                    Wallet  = newWallet,
                    OwnerId = ownerId
                };
                AddAndSave(shop);
                shopId = shop.Id;
            }
            else
            {
                shop = Get <ShopWallet>(w => w.Id == shopId, s => s.Wallet, s => s.Specialisations);
            }
            if (shop == null)
            {
                throw new BillingException("shop not found");
            }
            shop.Name           = name;
            shop.OwnerId        = ownerId;
            shop.Wallet.Balance = balance;
            shop.Comment        = comment;
            shop.Location       = location;
            var ls = BillingHelper.GetLifestyle(lifestyle);

            shop.LifeStyle = (int)ls;
            SaveContext();
            var dbSpecialisations = GetList <ShopSpecialisation>(s => s.ShopId == shop.Id);

            foreach (var shopspecialisation in dbSpecialisations)
            {
                Remove(shopspecialisation);
            }
            SaveContext();
            if (specialisations != null)
            {
                foreach (var specialisationId in specialisations)
                {
                    var specialisation = Get <Specialisation>(s => s.Id == specialisationId);
                    if (specialisation == null)
                    {
                        throw new Exception($"некорректные входные данные specialisation: {specialisation?.Id} ");
                    }
                    Add(new ShopSpecialisation {
                        ShopId = shopId, SpecialisationId = specialisationId
                    });
                }
                SaveContext();
            }
            shop = GetAsNoTracking <ShopWallet>(w => w.Id == shopId, s => s.Owner, s => s.Wallet, s => s.Specialisations);
            var dto = new ShopDto(ownerId, shop);

            return(dto);
        }
예제 #2
0
        private void ProcessBuyScoring(SIN sin, Sku sku, ShopWallet shop)
        {
            var type = sku.Nomenklatura.Specialisation.ProductType;

            if (type == null)
            {
                throw new Exception("type not found");
            }
            var manager = IoC.IocContainer.Get <IScoringManager>();

            switch (type.Alias)
            {
            case "Implant":
                manager.OnImplantBuy(sin, sku.Nomenklatura.Lifestyle);
                break;

            case "Food":
            case "EdibleFood":
                manager.OnFoodBuy(sin, sku.Nomenklatura.Lifestyle);
                break;

            case "Weapon":
                manager.OnWeaponBuy(sin, sku.Nomenklatura.Lifestyle);
                break;

            case "Pill":
                manager.OnPillBuy(sin, sku.Nomenklatura.Lifestyle);
                break;

            case "Magic":
                manager.OnMagicBuy(sin, sku.Nomenklatura.Lifestyle);
                break;

            case "Insurance":
                manager.OnInsuranceBuy(sin, sku.Nomenklatura.Lifestyle);
                break;

            case "Charity":
                manager.OnCharityBuy(sin, sku.Nomenklatura.Lifestyle);
                break;

            case "drone":
                manager.OnDroneBuy(sin, sku.Nomenklatura.Lifestyle);
                break;

            case "matrix":
                manager.OnMatrixBuy(sin, sku.Nomenklatura.Lifestyle);
                break;

            default:
                manager.OnOtherBuy(sin, sku.Nomenklatura.Lifestyle);
                break;
            }
            manager.OnShopLifestyle(sin, shop.LifeStyle);
        }
예제 #3
0
        protected Price CreateNewPrice(Sku sku, ShopWallet shop, SIN sin)
        {
            decimal modeldiscount;

            try
            {
                var eService = new EreminService();
                modeldiscount = eService.GetDiscount(sin.Character.Model, BillingHelper.GetDiscountType(sku.Nomenklatura.Specialisation.ProductType.DiscountType));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                modeldiscount = 1;
            }
            decimal discount = 1;

            if (sin.Passport.Mortgagee == sku.Corporation.Alias)
            {
                discount *= 0.9m;
            }
            discount *= modeldiscount;
            var currentScoring = sin.Scoring.CurrentFix + sin.Scoring.CurerentRelative;

            if (currentScoring == 0)
            {
                currentScoring = 1;
            }
            var price = new Price
            {
                Sku            = sku,
                Shop           = shop,
                BasePrice      = sku.Nomenklatura.BasePrice,
                CurrentScoring = currentScoring,
                DateCreated    = DateTime.Now.ToUniversalTime(),
                Discount       = discount,
                Sin            = sin,
                ShopComission  = BillingHelper.GetShopComission(shop.LifeStyle),
                ShopPrice      = BillingHelper.GetShopPrice(sku)
            };

            price.FinalPrice = BillingHelper.GetFinalPrice(price);
            Add(price);
            SaveContext();
            return(price);
        }
예제 #4
0
        public ShopDto(int modelId, ShopWallet shop) : base(modelId, shop)
        {
            if (shop == null)
            {
                return;
            }
            Lifestyle = new LifestyleDto
            {
                Id   = shop.LifeStyle,
                Name = BillingHelper.GetLifestyle(shop.LifeStyle).ToString()
            };

            if (shop.Specialisations == null)
            {
                Specialisations = new List <int>();
            }
            else
            {
                Specialisations = shop.Specialisations.Select(s => s.SpecialisationId).ToList();
            }
            if (shop.TrustedUsers == null)
            {
                TrustedUsers = new List <int>();
            }
            else
            {
                TrustedUsers = shop.TrustedUsers.Select(s => s.Model).ToList();
            }
            if (shop.Wallet == null)
            {
                return;
            }
            Balance  = shop.Wallet.Balance;
            Comment  = shop.Comment;
            Location = shop.Location;
        }
예제 #5
0
 public ShopDetailedDto(ShopWallet shop, List <QRDto> products, List <Specialisation> specialisations) : base(0, shop)
 {
     Products            = products;
     SpecialisationNames = specialisations.Select(s => s.Name).ToList();
 }