Exemple #1
0
 public ProductViewModel(Product product, int orderedQty)
 {
     Product = product;
     OrderedQuantityString = product.GetQuantityString(orderedQty);
 }
 public ProductEditionViewModel(Product product, ApplicationDbContext context, bool isNew)
 {
     Product = product;
     IsNew = isNew;
     RefreshTypes(context);
 }
Exemple #3
0
        private void CreateProductsSamples(ApplicationDbContext context)
        {
            if (context.Products.Any())
                return;
            Product pain = new Product();
            pain.Name = "Pain complet";
            pain.Description = "Pain farine complete T80";
            pain.Labels.Add(Product.Label.Ab);
            pain.PicturesSerialized= Path.Combine(Configurations.ProductsStockagePath, "pain.png");
            pain.Price = 15.5F;
	    pain.UnitPrice = 4;
            pain.Producer = context.Producers.First();
            pain.ProductUnit = Product.Unit.Kg;
            pain.RemainingStock = 10;
            pain.State = Product.ProductState.Enabled;
            pain.Type = Product.SellType.Piece;
            pain.WeekStock = 10;
            pain.Familly = context.ProductFamillys.First(x => x.FamillyName == "Pains");
            context.Add(pain);
            Product tomate = new Product();
            tomate.Name = "Tomates grappe";
            tomate.Description = "Avec ces tomates, c'est nous qui rougissons même si elles ne sont pas toutes nues!";
            tomate.Labels.Add(Product.Label.Ab);
            tomate.PicturesSerialized = Path.Combine(Configurations.ProductsStockagePath, "tomate.jpg");
	    tomate.Price = 3;
	    tomate.UnitPrice = 1.5F;
	    tomate.QuantityStep = 500;
            tomate.Producer = context.Producers.First();
            tomate.ProductUnit = Product.Unit.Kg;
            tomate.RemainingStock = 10;
            tomate.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            tomate.State = Product.ProductState.Enabled;
            tomate.Type = Product.SellType.Weigh;
            tomate.WeekStock = 10;
            context.Add(tomate);
            Product pommedeterre = new Product();
            pommedeterre.Name = "Pomme de terre";
            pommedeterre.Description = "Pataaaaaaaaaaaaaaaates!!";
            pommedeterre.Labels.Add(Product.Label.Ab);
            pommedeterre.PicturesSerialized = Path.Combine(Configurations.ProductsStockagePath, "pommedeterre.jpg");
            pommedeterre.Price = 1.99F;
	    pommedeterre.UnitPrice = 1.99F;
	    pommedeterre.QuantityStep = 1000;
            pommedeterre.Producer = context.Producers.First();
            pommedeterre.ProductUnit = Product.Unit.Kg;
            pommedeterre.RemainingStock = 10;
            pommedeterre.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            pommedeterre.State = Product.ProductState.Enabled;
            pommedeterre.Type = Product.SellType.Weigh;
            pommedeterre.WeekStock = 10;
            context.Add(pommedeterre);
            Product radis = new Product();
            radis.Name = "Radis";
            radis.Description = "Des supers radis (pour ceux qui aiment)";
            radis.Labels.Add(Product.Label.Ab);
            radis.PicturesSerialized = Path.Combine(Configurations.ProductsStockagePath, "radis.jpg");
            radis.Price = 0;
	    radis.UnitPrice = 4;
            radis.Producer = context.Producers.First();
            radis.ProductUnit = Product.Unit.Kg;
            radis.RemainingStock = 10;
            radis.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            radis.State = Product.ProductState.Enabled;
            radis.Type = Product.SellType.Piece;
            radis.WeekStock = 10;
            context.Add(radis);
            Product salade = new Product();
            salade.Name = "Salade";
            salade.Description = "Une bonne salade pour aller avec les bonnes tomates!";
            salade.Labels.Add(Product.Label.Ab);
            salade.PicturesSerialized = Path.Combine(Configurations.ProductsStockagePath, "salade.jpg");
            salade.UnitPrice = 0.80F;
	    salade.Price = 0;
            salade.Producer = context.Producers.First();
            salade.ProductUnit = Product.Unit.Kg;
            salade.RemainingStock = 10;
            salade.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            salade.State = Product.ProductState.Enabled;
            salade.Type = Product.SellType.Piece;
            salade.WeekStock = 10;
            context.Add(salade);

            //
            context.SaveChanges();
        }
 /**
  * Updates product remaining stock with the given quantity (< 0 || > 0)
  * Manages the stock according to the sell type of the product.
  */
 private void UpdateProductStock(Product product, int qty)
 {
     if (product.Type == Product.SellType.Piece)
     {
         product.RemainingStock += qty;
     }
     else
     {
         product.RemainingStock += ((decimal)((decimal) qty * (decimal) product.QuantityStep)) / 1000.0M;
     }
 }
Exemple #5
0
        private void CreateProductsSamples(ApplicationDbContext context)
        {
            if (context.Products.Any())
                return;
            Product pain = new Product();
            pain.Name = "Pain complet";
            pain.Description = "Pain farine complete T80";
            pain.Labels.Add(Product.Label.Ab);
            pain.PicturesSerialized = Path.Combine("pain.png");
            pain.Price = Convert.ToDecimal(15.5);
            pain.UnitPrice = 4;
            pain.TaxEnum = Product.TAX.Ten;
            pain.Producer = context.Producers.First();
            pain.ProductUnit = Product.Unit.Kg;
            pain.StockManagement = Product.StockType.Week;
            pain.RemainingStock = 10;
            pain.State = Product.ProductState.Enabled;
            pain.Type = Product.SellType.Piece;
            pain.WeekStock = 10;
            pain.Familly = context.ProductFamillys.First(x => x.FamillyName == "Pains");
            context.Add(pain);
            Product tomate = new Product();
            tomate.Name = "Tomates grappe";
            tomate.Description = "Avec ces tomates, c'est nous qui rougissons même si elles ne sont pas toutes nues!";
            tomate.Labels.Add(Product.Label.Ab);
            tomate.PicturesSerialized = Path.Combine("tomate.jpg");
            tomate.Price = 3;
            tomate.TaxEnum = Product.TAX.FiveFive;
            tomate.UnitPrice = Convert.ToDecimal(1.5);
            tomate.QuantityStep = 500;
            tomate.Producer = context.Producers.First();
            tomate.ProductUnit = Product.Unit.Kg;
            tomate.StockManagement = Product.StockType.Week;
            tomate.RemainingStock = 10;
            tomate.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            tomate.State = Product.ProductState.Enabled;
            tomate.Type = Product.SellType.Weigh;
            tomate.WeekStock = 10;
            context.Add(tomate);
            Product pommedeterre = new Product();
            pommedeterre.Name = "Pomme de terre";
            pommedeterre.Description = "Pataaaaaaaaaaaaaaaates!!";
            pommedeterre.Labels.Add(Product.Label.Ab);
            pommedeterre.PicturesSerialized = Path.Combine("pommedeterre.jpg");
            pommedeterre.Price = Convert.ToDecimal(1.99);
            pommedeterre.TaxEnum = Product.TAX.FiveFive;
            pommedeterre.UnitPrice = Convert.ToDecimal(1.99);
            pommedeterre.QuantityStep = 1000;
            pommedeterre.Producer = context.Producers.First();
            pommedeterre.ProductUnit = Product.Unit.Kg;
            pommedeterre.StockManagement = Product.StockType.Week;
            pommedeterre.RemainingStock = 10;
            pommedeterre.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            pommedeterre.State = Product.ProductState.Enabled;
            pommedeterre.Type = Product.SellType.Weigh;
            pommedeterre.WeekStock = 10;
            context.Add(pommedeterre);
            Product radis = new Product();
            radis.Name = "Radis";
            radis.Description = "Des supers radis (pour ceux qui aiment)";
            radis.Labels.Add(Product.Label.Ab);
            radis.PicturesSerialized = Path.Combine("radis.jpg");
            radis.Price = 0;
            radis.UnitPrice = 4;
            radis.TaxEnum = Product.TAX.FiveFive;
            radis.Producer = context.Producers.First();
            radis.ProductUnit = Product.Unit.Kg;
            radis.StockManagement = Product.StockType.Week;
            radis.RemainingStock = 10;
            radis.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            radis.State = Product.ProductState.Enabled;
            radis.Type = Product.SellType.Piece;
            radis.WeekStock = 10;
            context.Add(radis);
            Product salade = new Product();
            salade.Name = "Salade";
            salade.Description = "Une bonne salade pour aller avec les bonnes tomates!";
            salade.Labels.Add(Product.Label.Ab);
            salade.PicturesSerialized = Path.Combine("salade.jpg");
            salade.UnitPrice = Convert.ToDecimal(0.80);
            salade.TaxEnum = Product.TAX.FiveFive;
            salade.Price = 0;
            salade.Producer = context.Producers.First();
            salade.ProductUnit = Product.Unit.Kg;
            salade.StockManagement = Product.StockType.Week;
            salade.RemainingStock = 10;
            salade.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            salade.State = Product.ProductState.Enabled;
            salade.Type = Product.SellType.Piece;
            salade.WeekStock = 10;
            context.Add(salade);
            Product conserveTomate = new Product();
            conserveTomate.Name = "Bocaux de tomate 500ml";
            conserveTomate.Description = "Bocaux de tomate du jardin, cuillie mur et transformé dans la semaine. Bocaux en verre d'une contenance de 500ml";
            conserveTomate.PicturesSerialized = Path.Combine("ConserveTomate.jpg");
            conserveTomate.UnitPrice = Convert.ToDecimal(4);
            conserveTomate.TaxEnum = Product.TAX.None;
            conserveTomate.Price = 0;
            conserveTomate.Producer = context.Producers.First();
            conserveTomate.ProductUnit = Product.Unit.L;
            conserveTomate.StockManagement = Product.StockType.Fixed;
            conserveTomate.RemainingStock = 10;
            conserveTomate.Familly = context.ProductFamillys.First(x => x.FamillyName == "Légumes");
            conserveTomate.State = Product.ProductState.Enabled;
            conserveTomate.Type = Product.SellType.Piece;
            conserveTomate.WeekStock = 0;
            context.Add(conserveTomate);


            //
            context.SaveChanges();
        }
	/**
	 * Updates product remaining stock with the given quantity (< 0 || > 0)
	 * Manages the stock according to the sell type of the product.
	 */
	private void updateProductStock(Product product, int qty)
	{
	    if (product.Type == Product.SellType.Piece)
	    {
		product.RemainingStock += qty;
	    }
	    else
	    {
		product.RemainingStock += ((float)qty * product.QuantityStep) / 1000;
	    }
	}