How to add item in a request in asp.net c #?

0

I am developing a project that asks that items from a pizza restaurant be added to an order, not being a shopping cart, generating the order as if it were a cash program. I do not know how to add items to this request in a web project, any tips?
Remembering that the order should receive N pizzas and N drinks and the solution is being developed in visual studio 2013

follow the code!

 public class Pizza
 {
 public int PizzaID { get; set; }

    public string Sabor { get; set; }

    public double PrecoPizza { get; set; }

   public string Tamanho { get; set; }    
}

  public class Bebida
{
    public int BebidaID { get; set; }

    public string TipoBebida { get; set; }

    public string Sabor { get; set; }

    public string Tamanho { get; set; }

    public double PrecoBebida { get; set; }

   }

 public class Pedido
{
    public int PedidoID { get; set; }

    public double ValorTotal { get; set; }

    public string Status { get; set; }

    public int PedidoAtivo { get; set; }

    public string DescricaoPedido { get; set; }

    public virtual Pessoa Pessoa { get; set; }

    public int PessoaID { get; set; }


    public virtual ICollection<Bebida> Bebida { get; set; }

    public int BebidaID { get; set; }

    public virtual ICollection<Pizza> Pizza { get; set; }

    public int PizzaID { get; set; }
    public Pedido()
    {
        this.Pessoa = Pessoa;
        this.Bebida = new List<Bebida>();
        this.Pizza = new List<Pizza>();

    }
    
asked by anonymous 19.11.2014 / 21:25

1 answer

1

You have some problems with your modeling. As it is done, there is no way you can specify the quantity of pizzas and drinks ordered. The correct way would be a ratio of N to N between Orders and Drinks and Orders and Pizzas.

I'll fix it for you:

public class Pizza
{
    [Key]
    public int PizzaId { get; set; }
    [Required]
    public string Sabor { get; set; }
    [Required]
    public double PrecoPizza { get; set; }
    [Required]
    public TamanhoPizza Tamanho { get; set; } // Tamanho deve ser um Enum 
}

public class Bebida
{
    [Key]
    public int BebidaId { get; set; }
    [Required]
    public TipoBebida TipoBebida { get; set; }
    [Required]
    public string Sabor { get; set; }
    [Required]
    public TamanhoBebida Tamanho { get; set; }
    [Required]
    public double PrecoBebida { get; set; }

    public virtual ICollection<PedidoBebida> PedidoBebidas { get; set; }
}

public class Pedido
{
    [Key]
    public int PedidoId { get; set; }
    public int PessoaId { get; set; }

    public double ValorTotal { get; set; }
    public StatusPedido Status { get; set; }
    public Boolean PedidoAtivo { get; set; }
    public string DescricaoPedido { get; set; }

    public virtual Pessoa Pessoa { get; set; }

    public virtual ICollection<PedidoBebida> PedidoBebidas { get; set; }
    public virtual ICollection<PedidoPizza> PedidoPizzas { get; set; }
}

public class PedidoPizza 
{
    [Key]
    public int PedidoPizzaId { get; set; }
    public int PizzaId { get; set; }
    public int PedidoId { get; set; }

    [Required]
    public int Quantidade { get; set; }

    public virtual Pedido Pedido { get; set; }
    public virtual Pizza Pizza { get; set; }
}

public class PedidoBebida
{
    [Key]
    public int PedidoBebidaId { get; set; }
    public int BebidaId { get; set; }
    public int PedidoId { get; set; }

    [Required]
    public int Quantidade { get; set; }

    public virtual Pedido Pedido { get; set; }
    public virtual Bebida Bebida { get; set; }
}

The Enums:

public enum TamanhoPizza 
{
    Brotinho, 
    Media,
    Grande,
    Gigante
}

public enum TamanhoBebida
{
    250ml,
    300ml,
    600ml,
    1l,
    2l,
    2leMeio,
    3l
}

public enum TipoBebida
{
    AguaSemGas,
    AguaComGas,
    Refrigerante,
    Suco,
    Cerveja,
    Vinho,
}

public enum StatusPedido
{
    Realizado,
    EmPreparacao,
    EmEntrega,
    Finalizado
}
    
19.11.2014 / 21:37