1
I have a class called Matricula
. She gets a record of Aluno
and of Serie
.
I need to do a validation, where if the student is already enrolled in a registered series, the page presents a message stating that he is already enrolled and do not let him be enrolled again.
Below is the registration code:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
namespace bj_cursosonline.Models
{
public class Matricula
{
[Key]
public int ID { get; set; }
[Required(ErrorMessage = "Campo obrigatório!")]
[Display(Name = "Aluno")]
public int ALUNOSID { get; set; }
[Required(ErrorMessage = "Campo obrigatório!")]
[Display(Name = "Série")]
public int SERIESID { get; set; }
public virtual Series SERIES { get; set; }
public virtual Alunos ALUNO { get; set; }
}
}
Student Class:
public enum SEXOALUNO
{
MASCULINO, FEMININO
}
public class Alunos
{
[Key]
public int ID { get; set; }
[Display(Name = "Nome")]
[Required(ErrorMessage = "Campo obrigatório!")]
public string NOME { get; set; }
[Display(Name = "Sexo")]
[Required(ErrorMessage = "Campo obrigatório!")]
public SEXOALUNO? SEXO { get; set; }
[Required(ErrorMessage = "Campo obrigatório!")]
[Display(Name = "Data de Nascimento")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
[DataType(DataType.Date, ErrorMessage = "Data em formato inválido!")]
public DateTime DATANASCIMENTO { get; set; }
public virtual ICollection<Matricula>
Matricula
{ get; set; }
}
Serial Class:
public enum TURMA
{
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
}
public enum TURNO
{
MANHÃ, TARDE, NOITE
}
public class Series
{
[Key]
public int ID { get; set; }
[Required(ErrorMessage = "Campo Obrigatório!")]
[StringLength(50)]
[Display(Name = "Descrição:")]
public string DESCRICAO { get; set; }
[Display(Name = "Turma:")]
public TURMA? TURMA { get; set; }
[Display(Name = "Turno: ")]
public TURNO? TURNO { get; set; }
[Required(ErrorMessage = "Campo Obrigatório!")]
[Display(Name = "Número da Sala:")]
public int NUMSALA { get; set; }
public virtual ICollection<Avaliacoes>
Avaliacoes
{ get; set; }
public virtual ICollection<Matricula>
Matricula
{ get; set; }
}
Would you be able to put the SERIE and STUDENT class as well? In addition you are using what to carry out your queries in the Database?
– Jeferson Almeida
The best way is by database. Via C# is much more code.
– Oralista de Sistemas
you could add a Unique index to your table, but check your business rule, for example: imagine that a student enrolled in the year 2015, did not complete the grade, and now in 2017 will enroll again. Would you have to delete the previous number plate? You’d lose his previous history ?
– Rovann Linhalis