public static BaseProductModel ToBaseProduct(this Product product) { BaseProductModel _result = new BaseProductModel(); _result.Id = product.Id; _result.ProductCode = product.ProductCode; _result.ProductName = product.ProductName; _result.ProductGroupId = product.ProductGroupId; _result.BrandId = product.BrandId; _result.UnitId = product.UnitId; _result.SizeId = product.SizeId; _result.ModelNumberId = product.ModelNumberId; _result.TaxId = product.TaxId; _result.TaxApplicableOn = product.TaxApplicableOn; _result.PurchaseRate = product.PurchaseRate; _result.SalesRate = product.SalesRate; _result.MRP = product.MRP; _result.MinimumStock = product.MinimumStock; _result.MaximumStock = product.MaximumStock; _result.ReOrderLevel = product.ReOrderLevel; _result.GodownId = product.GodownId; _result.RackId = product.RackId; _result.IsAllowBatch = product.IsAllowBatch; _result.IsMultipleUnit = product.IsMultipleUnit; _result.IsBOM = product.IsBOM; _result.IsOpeningStock = product.IsOpeningStock; _result.Narration = product.Narration; _result.IsActive = product.IsActive; _result.IsShowRemember = product.IsShowRemember; _result.PartNumber = product.PartNumber; _result.CreatedDate = product.CreatedDate; _result.ModifiedDate = product.ModifiedDate; return(_result); }
public IEnumerable <BaseProductModel> ParseProducts(string[] lines) { var list = new List <BaseProductModel>(); ProductCategoryModel currentCategory = null; var categories = GetCategories(); int maxPriority = lines.Length * 10; int priority = 0; for (int i = 0; i < lines.Length; i++) { string s = lines[i].Trim(); if (String.IsNullOrEmpty(s) == false) { // Should be category if (s.EndsWith(":")) { // First product in list should be first one priority = maxPriority; s = s.Substring(0, s.Length - 1).Trim(); try { currentCategory = categories.First(x => x.Name.Equals(s, StringComparison.OrdinalIgnoreCase)); } catch (InvalidOperationException ioex) { throw new Exception("Category not found: `" + s + "`", ioex); } } else { if (currentCategory == null) { throw new ArgumentException("First line should be category. Must ends with semicolon (:)"); } // Parse product string[] ar = s.Split(new char[] { '\t' }); if (ar.Length != 2) { throw new ArgumentException("Line must contain NAME and PRICE: " + s); } // Possible prices: "12" or "20 / 30 /40" string[] prices = ar[1].Split(new char[] { '/' }); //string name = ar[0].Trim(); //string[] subName = new string[0]; //if (prices.Length > 1) //{ //} for (int j = 0; j < prices.Length; j++) { var p = new BaseProductModel(); p.CultureName = "LT"; p.Name = ar[0].Trim(); p.ProductCategoryId = currentCategory.Id; p.Price = ParsePrice(prices[j]); p.Priority = priority; list.Add(p); priority -= 5; } } } } return(list); }