public void AddPriceList(PriceList priceList) { var priceListRep = new PriceListRepository(); var category = _stockService.GetCategoryByName(priceList.Product.Category.Name); if (category == null) { var categoryAdd = new Category { Name = priceList.Product.Category.Name }; var categoryRep = new CategoryRepository(); category = categoryRep.Add(categoryAdd); } var product = _stockService.GetProductByName(priceList.Product.Name); if (product == null) { var productAdd = new Product { Name = priceList.Product.Name, Category = category }; var productRep = new ProductRepository(); product = productRep.Add(productAdd); } priceList.Product = product; priceListRep.Add(priceList); }
//public void UpdateRestTrxFee() //{ // try // { // var list =TransactionsViewRepository.GetMany( // x => x.Fee == 0 && x.Amount > 0 // && x.TransactionDate.Year >= 2014 // //x.TransactionTypeId == (byte) BillingEnums.eTransactionTypes.InitialSubscriptionPayment && // && (x.PaymentMethodId == (byte)BillingEnums.ePaymentMethods.Credit_Card) || x.PaymentMethodId == (byte)BillingEnums.ePaymentMethods.Saved_Instrument).ToList(); // var cnt = 0; // foreach (var row in list) // { // var trx = _paypalManageServies.GetRestPaymentDetails(row.ExternalTransactionID); // //if(trx ==null || trx.Ack != AckCodeType.SUCCESS) continue; // //var fee = trx.PaymentTransactionDetails.PaymentInfo.FeeAmount.value; // //if(fee==null) continue; // //var entity = TransactionRepository.GetById(row.TransactionId); // //if(entity==null) continue; // //entity.Fee = Convert.ToDecimal(fee); // //entity.UpdateDate = DateTime.Now; // //if(!TransactionRepository.UnitOfWork.CommitAndRefreshChanges()) continue; // cnt++; // } // } // catch (Exception) // { // } //} //public void ImportPrices() //{ // using (var context = new lfeAuthorEntities()) // { // #region courses // var courses = context.Courses.Where(x => !x.IsFreeCourse).ToList(); // foreach (var course in courses) // { // var courseId = course.Id; // BILL_ItemsPriceList entity; // if (course.PriceUSD != null) // { // if (context.BILL_ItemsPriceList.Any(x => x.ItemId == courseId // && x.ItemTypeId == (byte)BillingEnums.ePurchaseItemTypes.COURSE // && x.PriceTypeId == (byte)BillingEnums.ePricingTypes.ONE_TIME // && x.CurrencyId == DEFAULT_CURRENCY_ID) // ) continue; // entity = new BILL_ItemsPriceList // { // ItemId = courseId // ,ItemTypeId = (byte)BillingEnums.ePurchaseItemTypes.COURSE // ,PriceTypeId = (byte)BillingEnums.ePricingTypes.ONE_TIME // ,Price = (decimal) course.PriceUSD // ,CurrencyId = DEFAULT_CURRENCY_ID // ,IsDeleted = false // ,AddOn = DateTime.Now // }; // context.BILL_ItemsPriceList.Add(entity); // context.SaveChanges(); // } // if (course.MonthlySubscriptionPriceUSD == null) continue; // if (context.BILL_ItemsPriceList.Any(x => x.ItemId == courseId // && x.ItemTypeId == (byte)BillingEnums.ePurchaseItemTypes.COURSE // && x.PriceTypeId == (byte)BillingEnums.ePricingTypes.SUBSCRIPTION // && x.PeriodTypeId == (byte)BillingEnums.eBillingPeriodType.MONTH // && x.CurrencyId == DEFAULT_CURRENCY_ID) // ) continue; // entity = new BILL_ItemsPriceList // { // ItemId = courseId // ,ItemTypeId = (byte)BillingEnums.ePurchaseItemTypes.COURSE // ,PriceTypeId = (byte)BillingEnums.ePricingTypes.SUBSCRIPTION // ,PeriodTypeId = (byte)BillingEnums.eBillingPeriodType.MONTH // ,Price = (decimal) course.MonthlySubscriptionPriceUSD // ,CurrencyId = DEFAULT_CURRENCY_ID // ,IsDeleted = false // ,AddOn = DateTime.Now // }; // context.BILL_ItemsPriceList.Add(entity); // context.SaveChanges(); // } // #endregion // #region bundle // var bundles = context.CRS_Bundles.ToList(); // foreach (var bundle in bundles) // { // var courseId = bundle.BundleId; // BILL_ItemsPriceList entity; // if (bundle.Price != null) // { // if (context.BILL_ItemsPriceList.Any(x => x.ItemId == courseId // && x.ItemTypeId == (byte)BillingEnums.ePurchaseItemTypes.BUNDLE // && x.PriceTypeId == (byte)BillingEnums.ePricingTypes.ONE_TIME // && x.CurrencyId == DEFAULT_CURRENCY_ID) // ) continue; // entity = new BILL_ItemsPriceList // { // ItemId = courseId // ,ItemTypeId = (byte)BillingEnums.ePurchaseItemTypes.BUNDLE // ,PriceTypeId = (byte)BillingEnums.ePricingTypes.ONE_TIME // ,Price = (decimal) bundle.Price // ,CurrencyId = DEFAULT_CURRENCY_ID // ,IsDeleted = false // ,AddOn = DateTime.Now // }; // context.BILL_ItemsPriceList.Add(entity); // context.SaveChanges(); // } // if (bundle.MonthlySubscriptionPrice == null) continue; // if (context.BILL_ItemsPriceList.Any(x => x.ItemId == courseId // && x.ItemTypeId == (byte)BillingEnums.ePurchaseItemTypes.BUNDLE // && x.PriceTypeId == (byte)BillingEnums.ePricingTypes.SUBSCRIPTION // && x.PeriodTypeId == (byte)BillingEnums.eBillingPeriodType.MONTH // && x.CurrencyId == DEFAULT_CURRENCY_ID) // ) continue; // entity = new BILL_ItemsPriceList // { // ItemId = courseId // ,ItemTypeId = (byte)BillingEnums.ePurchaseItemTypes.BUNDLE // ,PriceTypeId = (byte)BillingEnums.ePricingTypes.SUBSCRIPTION // ,PeriodTypeId = (byte)BillingEnums.eBillingPeriodType.MONTH // ,Price = (decimal) bundle.MonthlySubscriptionPrice // ,CurrencyId = DEFAULT_CURRENCY_ID // ,IsDeleted = false // ,AddOn = DateTime.Now // }; // context.BILL_ItemsPriceList.Add(entity); // context.SaveChanges(); // } // #endregion // } //} public void UpdateFreeCourses() { try { var lines = CourseRepository.GetMany(x => x.IsFreeCourse).ToList(); foreach (var course in lines) { var current = course; var isExists = PriceListRepository.IsAny(x => x.ItemId == current.Id && x.ItemTypeId == (byte)BillingEnums.ePurchaseItemTypes.COURSE && x.PriceTypeId == (byte)BillingEnums.ePricingTypes.FREE && !x.IsDeleted); if (isExists) { continue; } var dto = new PriceLineDTO { ItemId = course.Id , ItemType = BillingEnums.ePurchaseItemTypes.COURSE , PriceType = BillingEnums.ePricingTypes.FREE , Price = 0 , Currency = new BaseCurrencyDTO { CurrencyId = DEFAULT_CURRENCY_ID } }; var entity = dto.Token2PriceLineEntity(); PriceListRepository.Add(entity); PriceListRepository.UnitOfWork.CommitAndRefreshChanges(); } } catch (Exception) { throw; } }