public List <Models.FitModel> Fit(List <Models.FitModel> all) { var result = new List <Models.FitModel>(); Random rnd = new Random(); int Length = all.Count; int TempWeight; double TempPrice; int TempKcal; int sumkcal = 0; int NumOfIngredients = 0; do { result.Add(all[rnd.Next(Length)]); //wylosowanie jednego elementu nie działa TempWeight = rnd.Next(1, 5); //Losowanie Wagi co 100 gram TempPrice = TempWeight * result[NumOfIngredients].Price; TempPrice = Math.Round(value: TempPrice, digits: 2); TempKcal = TempWeight * result[NumOfIngredients].Kcal; sumkcal += TempKcal; result[NumOfIngredients].Price = float.Parse(TempPrice.ToString()); result[NumOfIngredients].Kcal = TempKcal; result[NumOfIngredients].Weight = TempWeight * 100; NumOfIngredients++; }while (sumkcal < UserKcal); return(result); }
public TempPrice GetTempPrice(string id, string value, string type, out decimal price) { ProductPrice pP = GetById(Convert.ToInt32(id)); TempPrice tP = new TempPrice(); decimal Price; decimal PriceSell; decimal CTR; string tempvalue = value.Replace(",", "."); if (type == "1") { Price = Convert.ToDecimal(tempvalue); } else if (type == "2") { Price = (-((pP.Product.BasePrices[0].PricePurchase * pP.Product.BasePrices[0].PricePurchaseCurrency.Value) / (((Convert.ToDecimal(tempvalue) / 100) - 1) * ((100 - pP.PriceList.Discount.MaxDiscount) / 100))) / pP.PriceSellCurrency.Value); } else { Price = pP.Price * (1 + (Convert.ToDecimal(tempvalue) / 100)); } PriceSell = ((Price * pP.PriceCurrency.Value) * (100 - pP.PriceList.Discount.MaxDiscount) / 100) / pP.PriceSellCurrency.Value; if (!(pP.Product.BasePrices[0].PricePurchase == 0)) { CTR = (1 - ((pP.Product.BasePrices[0].PricePurchase * pP.Product.BasePrices[0].PricePurchaseCurrency.Value) / (PriceSell * pP.PriceSellCurrency.Value))) * 100; } else { CTR = 0; } price = Price; tP.NewPrice = pP.PriceCurrency.Description + " " + Price.ToString("#,##0.00"); tP.NewCtr = CTR.ToString("##0.00") + " %"; tP.OriginalPrice = pP.PriceCurrency.Description + " " + pP.Price.ToString("#,##0.00"); tP.NewPriceWF = Price.ToString(); tP.OriginalPriceWF = pP.Price; return(tP); }