0
I am trying to list my bookings by different administrators. However, as I did, it lists all bookings.
That’s the method I’m using:
public ActionResult Index()
    {
        Administrador administrador = db.Administradores.FirstOrDefault(a => a.Email == User.Identity.Name);
        if (administrador != null)
        {
            return View(db.Reservas.ToList());
        }
        else
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
    }
Reserve Class:
public class Reserva
{
    [Key]
    public int ReservaID { get; set; }
    [Required(ErrorMessage = "Preencha o horário para reserva")]
    [DisplayName("Horário")]
    [DataType(DataType.Time)]
    public string Horario { get; set; }
    [Required(ErrorMessage = "Preencha o limite de pedidos/hora")]
    [DisplayName("Limite de Pedidos/Hora")]
    public int LimitePedidos { get; set; }
    [Required(ErrorMessage = "Preencha a mesa")]
    [DisplayName("Mesa")]
    [StringLength(10, MinimumLength = 1, ErrorMessage = "A mesa deve ter no máximo 10 caracteres")]
    public string Mesa { get; set; }
    [Required(ErrorMessage = "Preencha o valor da reserva")]
    [DisplayName("Valor")]
    public double Valor { get; set; }
    public virtual ICollection<Restaurante> Restaurantes { get; set; }
}
Restaurant Class:
public abstract class Restaurante
{
    [Key]
    public int RestauranteID { get; set; }
    [Required(ErrorMessage = "Preencha o nome do Restaurante")]
    [DisplayName("Restaurante")]
    [StringLength(50, MinimumLength = 5, ErrorMessage = "O nome do restaurante deve ter entre 5 e 50 caracteres.")]
    public string Nome { get; set; }
    [Required(ErrorMessage = "Preencha o tipo de cozinha")]
    [DisplayName("Cozinha")]
    public int CozinhaID { get; set; }
    public virtual Cozinha Cozinha { get; set; }
    [Required(ErrorMessage = "Preencha o telefone")]
    [DisplayName("Telefone")]
    [StringLength(12, MinimumLength = 10, ErrorMessage = "O número de telefone deve haver 12 caracteres.")]
    public string Telefone { get; set; }
    [Required(ErrorMessage = "Preencha o CNPJ")]
    [DisplayName("Cnpj")]
    [StringLength(18, MinimumLength = 18, ErrorMessage = "O CNPJ deve haver no máximo, 18 caracteres.")]
    public string Cnpj { get; set; }
    [Required(ErrorMessage = "Preencha o CEP")]
    [DisplayName("CEP")]
    [StringLength(9, MinimumLength = 8, ErrorMessage = "O CEP deve haver no máximo 9 caracteres.")]
    public string Cep { get; set; }
    [Required(ErrorMessage = "Preencha a Cidade")]
    [DisplayName("Cidade")]
    [StringLength(50, MinimumLength = 5, ErrorMessage = "A cidade deve ter entre 5 e 50 caracteres.")]
    public string Cidade { get; set; }
    [Required(ErrorMessage = "Preencha o Estado")]
    [DisplayName("Estado")]
    [StringLength(2, MinimumLength = 2, ErrorMessage = "A sigla do estado deve haver 2 caracteres.")]
    public string Estado { get; set; }
    [Required(ErrorMessage = "Preencha o Bairro")]
    [DisplayName("Bairro")]
    [StringLength(50, MinimumLength = 5, ErrorMessage = "O bairro deve ter entre 5 e 50 caracteres.")]
    public string Bairro { get; set; }
    [Required(ErrorMessage = "Preencha a Rua")]
    [DisplayName("Rua")]
    [StringLength(50, MinimumLength = 5, ErrorMessage = "A rua deve ter entre 5 e 50 caracteres.")]
    public string Rua { get; set; }
    [Required(ErrorMessage = "Preencha a número do estabelecimento")]
    [DisplayName("Número")]
    public int NumRua { get; set; }
    [Required(ErrorMessage = "Preencha o nome do responsável pelo estabelecimento")]
    [DisplayName("Nome")]
    [StringLength(50, MinimumLength = 5, ErrorMessage = "O nome do responsável deve ter entre 5 e 50 caracteres.")]
    public string NomeResp { get; set; }
    [Required(ErrorMessage = "Preencha o sobrenome do responsável pelo estabelecimento")]
    [DisplayName("Sobrenome")]
    [StringLength(50, MinimumLength = 5, ErrorMessage = "O sobrenome do responsável deve ter entre 5 e 50 caracteres.")]
    public string SobrenomeResp { get; set; }
    [Required(ErrorMessage = "Preencha o Email")]
    [DisplayName("Email")]
    [DataType(DataType.EmailAddress)]
    [EmailAddress(ErrorMessage = "E-mail inválido")]
    [StringLength(255, MinimumLength = 3, ErrorMessage = "O email deve ter entre 3 e 255 caracteres.")]
    public string Email { get; set; }
    [Required(ErrorMessage = "Preencha o Celular")]
    [DisplayName("Telefone")]
    [StringLength(15, MinimumLength = 10, ErrorMessage = "O número de celular deve haver entre 10 e 15 caracteres.")]
    public string Celular { get; set; }
    [Required(ErrorMessage = "Preencha a senha")]
    [DisplayName("Senha")]
    [StringLength(50, MinimumLength = 3, ErrorMessage = "A senha deve ter entre 3 e 50 caracteres.")]
    [DataType(DataType.Password)]
    public string Senha { get; set; }
    public virtual Usuario Usuario { get; set; }
    [DisplayName("Foto")]
    public string Foto { get; set; }
    public virtual Reserva Reserva { get; set; }
    public virtual Produto Produto { get; set; }
}
Restaurant is abstract, because the Administrator class inherits all fields from it. But it is empty. 
within Reservations is there anything that indicates that it is from a particular Administrator? , put the Reservations and Administrator classes in your question
– novic
There you go. I put.
– Allan Fernandes
Are you recording this right there? like there are values in Restaurant? #strange
– novic
There is, it’s just an Abstract. It’s a mother class. The registrations, edits, I do all with the Administrator class, who inherits the Restaurant class fields. But in the database is saved in the table restaurant. =)
– Allan Fernandes
So I would not do so, because in the Administrator class there are no additional fields and I see no logic for that. If you have to take the relationship between the fields that in your Restaurant class does not have!?
– novic
But it’s just a detail that can be changed. The question is, I want to list reservations from the administrator. That’s it. But I don’t know how to write it within the method.
– Allan Fernandes
What is the field (or key) that relates Reserve and Restaurant, thinking of Class model (logical) related to bank model (physical) ???
– novic
As written in the code above, the restaurant takes the Reservaid attribute from Reserve. And reservation has restaurants.
– Allan Fernandes
Where the Reservarid field within Restaurant? just remembering in Entity Framework it has to exist! (different for example from Nhibernate)
– novic
I will put. Right after that, what is the procedure for listing? The method, in this case.
– Allan Fernandes
First thing, tidy up your entire layout, placing the keys and structuring your base to the
ORM Entity Framework. Has a lineAdministrador administrador = db.Administradores.FirstOrDefault(a => a.Email == User.Identity.Name);If you bring in the administrator, you’ll have reservations and a restaurant, all for relationships. Without the relationship working gets complicated and with them is the answer of what you need.– novic