public InsuranceDto GetInsurance(int modelId) { var dbinsurance = Get <ProductType>(p => p.Alias == ProductTypeEnum.Insurance.ToString()); if (dbinsurance == null) { throw new Exception("insurance type not found"); } var sin = GetSINByModelId(modelId, s => s.Passport); if (sin == null) { throw new Exception("sin not found"); } var insurance = new InsuranceDto { BuyTime = DateTime.MinValue, SkuName = "Страховка отсутствует", LifeStyle = "Страховка отсутствует", ShopName = "Страховка отсутствует", PersonName = $"{sin.Passport?.PersonName}" }; var lastIns = GetInsurance(modelId, r => r.Sku.Nomenklatura, r => r.Shop); if (lastIns != null) { insurance.SkuId = lastIns.SkuId; insurance.BuyTime = lastIns.DateCreated; insurance.SkuName = lastIns.Sku.Name; insurance.LifeStyle = BillingHelper.GetLifestyle(lastIns.Sku.Nomenklatura.Lifestyle).ToString(); insurance.ShopName = lastIns.Shop.Name; } return(insurance); }
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); }
public NomenklaturaDto CreateOrUpdateNomenklatura(int id, string name, string code, int specialisationId, int lifestyle, decimal baseprice, int basecount, string description, string pictureurl, int externalId = 0) { Nomenklatura nomenklatura = null; if (id > 0) { nomenklatura = Get <Nomenklatura>(n => n.Id == id); } if (nomenklatura == null) { nomenklatura = new Nomenklatura(); nomenklatura.PictureUrl = UrlNotFound; nomenklatura.Code = string.Empty; Add(nomenklatura); } nomenklatura.Name = name; nomenklatura.Code = code; nomenklatura.BasePrice = baseprice; nomenklatura.Description = description; nomenklatura.PictureUrl = pictureurl; if (externalId != 0) { nomenklatura.ExternalId = externalId; } nomenklatura.BaseCount = basecount; Specialisation specialisation = null; if (specialisationId > 0) { specialisation = Get <Specialisation>(p => p.Id == specialisationId); } else { specialisation = Get <Specialisation>(p => p.Id == nomenklatura.SpecialisationId); } if (specialisation == null) { throw new BillingException("specialisation not found"); } nomenklatura.SpecialisationId = specialisation.Id; nomenklatura.Lifestyle = lifestyle; nomenklatura.Lifestyle = (int)BillingHelper.GetLifestyle(nomenklatura.Lifestyle); SaveContext(); nomenklatura = GetAsNoTracking <Nomenklatura>(n => n.Id == nomenklatura.Id, n => n.Specialisation.ProductType); if (nomenklatura == null) { throw new Exception("Создать nomenklatura не получилось"); } return(new NomenklaturaDto(nomenklatura, true)); }
protected void RecalculateRenta(Renta renta, string qrDecoded, SIN newsin) { renta.SinId = newsin.Id; var anon = GetAnon(newsin.Character.Model); renta.CurrentScoring = newsin.Scoring.CurerentRelative + newsin.Scoring.CurrentFix; var gmdescript = BillingHelper.GetGmDescription(newsin.Passport, renta.Sku, anon); _ereminService.UpdateQR(qrDecoded, renta.BasePrice, BillingHelper.GetFinalPrice(renta), gmdescript, renta.Id, BillingHelper.GetLifestyle(renta.LifeStyle)).GetAwaiter().GetResult(); SaveContext(); }