How to add item in an order in Asp.net c#?

Asked

Viewed 792 times

1

I am developing a project that asks that items from a pizzeria be added to an order, not being a shopping cart, generating the order as if it were a cashier program.
I don’t know how to add items to this request in a web project, some hint?
Recalling that the order should receive N pizzas and N drinks and the solution is being developed in visual studio 2013

follows 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>();

    }

1 answer

2

There are some problems in your modeling. The way it is done, there is no way you specify the amount of pizzas and drinks ordered. The correct way would be a N to N relationship 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; }
}

Os 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
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.