Time Questions Area

3

I'm developing an application that should provide an environment where the following functions are performed:

Administrator
- Register questions
- Edit user
- Viewing Answers - View evidence
- Entered note

User
- If you register
- Fills proof

In this environment the time will be timed the basis of the time of start of the race that will be related to the time filled by the administrator in the evidence register. I thought of validating the time by jQuery just inserting in the database the initial time of the test and comparing regardless of whether the user closed or not the browser. Since I will work with ajax, I will not worry about the user disabling or not the javascript. Each question will be on a screen that will be made available via ajax and if it closes the browser and reopens, it will return to the one that stopped (without bringing what it filled in).

I created the following domains:

Student

public class Bolsa_Aluno
    {
        public int ID { get; set; }

        [Required(ErrorMessage = "Nome deve ser preenchido")]
        public string Nome { get; set; }

        [Required(ErrorMessage = "Email deve ser preenchido")]
        [RegularExpression(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", ErrorMessage = "E-mail inválido")]
        public string Email { get; set; }

        [Required(ErrorMessage = "CPF deve ser preenchido")]
        [StringLength(11, ErrorMessage = "Digite apenas 11 números")]
        public string CPF { get; set; }

        [Required(ErrorMessage = "Telefone deve ser preenchido")]
        [StringLength(15, ErrorMessage = "Digite no máximo 15 caracteres")]
        public string Telefone { get; set; }

        public string Curso { get; set; }

        public virtual int AlunoProvaID { get; set; }
        public virtual Bolsa_AlunoProva AlunoProva { get; set; }
    }

StudentProva

public class Bolsa_AlunoProva
    {
        public int ID { get; set; }
        public int Nota { get; set; }
        public DateTime DataInicial { get; set; }
        public DateTime DataFinal { get; set; }

        public virtual int AlunoID { get; set; }
        public virtual Bolsa_Aluno Aluno { get; set; }

        public virtual int ProvaID { get; set; }
        public virtual Bolsa_Prova Prova { get; set; }

        public virtual ICollection<Bolsa_AlunoResposta> AlunoResposta { get; set; }
    }

StudentAnswer

public class Bolsa_AlunoResposta
    {
        public int ID { get; set; }
        public string Resposta { get; set; }

        public virtual int AlunoProvaID { get; set; }
        public virtual Bolsa_AlunoProva AlunoProva { get; set; }

        public virtual ICollection<Bolsa_Pergunta> Pergunta { get; set; }
    }

Question

public class Bolsa_Pergunta
    {
        public int ID { get; set; }

        [Required(ErrorMessage = "Pergunta deve ser preenchido")]
        public string Pergunta { get; set; }

        public virtual int AlunoProvaID { get; set; }
        public virtual Bolsa_AlunoProva AlunoProva { get; set; }

        public virtual int AlunoRespostaID { get; set; }
        public virtual Bolsa_AlunoResposta AlunoResposta { get; set; }
    }

Proof

public class Bolsa_Prova
    {
        public int ID { get; set; }

        [Required(ErrorMessage = "Tempo deve ser preenchido em minutos")]
        public int Tempo { get; set; }

        [Required(ErrorMessage = "Quantidade de Perguntas deve ser preenchido")]
        public int QuantidadePerguntas { get; set; }

        public string Nome { get; set; }
        public string Bandeira { get; set; }

        public virtual ICollection<Bolsa_Pergunta> Pergunta { get; set; }
    }

My question is the following. Is this the best validation and storage practice telling you that I do not have to worry too much about security?

Is it a bad practice to save each response individually in the database to "keep the session" in case the user closes the browser?

When I run migration (working with code-first), I came across the following relationship error:

  

Unable to determine the main end of an association between the   types 'Domain.Provider' and 'Domain.Provider'. The   principal of this association must be explicitly configured using   either the relationship fluent API or data annotations.

Would it be correct to apply the [Required] tag to Bolsa_AlunoProva as a solution in the public virtual Bolsa_Prova Prova { get; set; } ?

    
asked by anonymous 08.10.2014 / 22:23

1 answer

3

Is this the best validation and storage practice telling you that I do not have to worry about security extremely?

The security aspect is more connected to the Controller than to the Model itself, therefore to what has been indicated, there are not necessarily security issues in your Model .

Is it a bad practice to save each response individually in the database to "keep the session" in case the user closes the browser?

No, it is recommended. Incidentally, in case of documentary evidence, it would be ideal because you can use a time stamp from the server to say exactly on what day and time the response was received.

When I run migration (working with code-first), I came across the following relationship error ...

The mistake happens because you allow a Student to have only one test. Change to the following:

    // Retire esse ID
    // public virtual int AlunoProvaID { get; set; }
    public virtual ICollection<Bolsa_AlunoProva> AlunoProvas { get; set; }

Even if the student can only have one test, the strict 1 to 1 association is making the Entity Framework get lost because it has no way to determine the foreign keys right. It would look something like:

create table Aluno (
    ID int primary key, 
    AlunoProvaID int foreign key references AlunoProva (ID)
)

create table AlunoProva (
    ID int primary key, 
    AlunoID int foreign key references Aluno (ID)
)

Would it be correct to apply the [Required] tag to Bolsa_AlunoProva as a solution to item public virtual Bolsa_Prova Prova { get; set; } ?

This does not solve the problem (see above).

    
08.10.2014 / 22:40