Esempio n. 1
0
            protected override ValidationResult IsValid(object value, ValidationContext context)
            {
                PizzaModel pizza = (PizzaModel)context.ObjectInstance;

                if (pizza.ToppingIDs == null || pizza.MaxToppings == null || pizza.ToppingIDs.Count() <= pizza.MaxToppings)
                {
                    return(ValidationResult.Success);
                }
                else
                {
                    return(new ValidationResult($"{pizza.MaxToppings} Toppings max"));
                }
            }
Esempio n. 2
0
            protected override ValidationResult IsValid(object value, ValidationContext context)
            {
                PizzaModel pizza = (PizzaModel)context.ObjectInstance;

                if (pizza.PresetID == null || pizza.ToppingIDs == null)
                {
                    return(ValidationResult.Success);
                }
                else
                {
                    return(new ValidationResult("Cannot have both a Preset and a list of Toppings"));
                }
            }
        public static PizzaModel Map(Pizza pizza)
        {
            if (pizza == null)
            {
                return(null);
            }
            PizzaModel p = new PizzaModel();

            p.SizeID     = pizza.Size.ID;
            p.Size       = pizza.Size.Name;
            p.CrustID    = pizza.Crust.ID;
            p.Crust      = pizza.Crust.Name;
            p.PresetID   = pizza.Preset.ID;
            p.Preset     = pizza.Preset.Name;
            p.ToppingIDs = pizza.Toppings.Select(x => x.ID).ToList();
            p.Toppings   = pizza.Toppings.Select(x => x.Name).ToList();
            p.Price      = pizza.Price;
            p.Amount     = pizza.Amount;

            return(p);
        }
        public static Pizza Map(PizzaModel pizza)
        {
            if (pizza == null)
            {
                return(null);
            }
            Pizza p = new Pizza();

            p.Size   = (pizza.SizeID, pizza.Size);
            p.Crust  = (pizza.CrustID, pizza.Crust);
            p.Preset = (pizza.PresetID, pizza.Preset);
            var temp = new List <(int, string)>();

            for (int i = 0; i < pizza.ToppingIDs.Count; i++)
            {
                temp.Add((pizza.ToppingIDs[i], pizza.Toppings[i]));
            }
            p.Toppings = temp;
            p.Price    = pizza.Price;
            p.Amount   = pizza.Amount;

            return(p);
        }