public List <StudentSubject> StudentBySubjects(Guid idStudent)   //Meu Funciona OK, torna llista dels IDs dels students i les ID de les seves Subjects.
        {
            var repo     = DepCon.Resolve <IRepository <StudentSubject> >();
            var entityId = repo.QueryAll().Where(e => e.StudentId == idStudent).ToList();

            return(entityId);
        }
Esempio n. 2
0
        public List <StudentSubject> StudentBySubjects(Guid idStudent)
        {
            var repo     = DepCon.Resolve <IRepository <StudentSubject> >();
            var entityId = repo.QueryAll().Where(e => e.StudentId == idStudent).ToList();

            return(entityId);
        }
Esempio n. 3
0
        public Exam FindExam(Guid idExam)
        {
            var repo   = DepCon.Resolve <IRepository <Exam> >();
            var entity = repo.QueryAll().FirstOrDefault(x => x.Id == idExam);

            return(entity);
        }
Esempio n. 4
0
        public static ValidationResult <string> ValidateExist(string dni)
        {
            var output = new ValidationResult <string>()
            {
                IsSuccess = true
            };

            if (string.IsNullOrEmpty(dni))
            {
                output.IsSuccess = false;
                output.Errors.Add("El DNI no puede estar vacío");
            }
            else if (dni.Length < 9)
            {
                output.IsSuccess = false;
                output.Errors.Add("El DNI no tiene un formato correcto");
            }

            #region check existence
            var repo          = DepCon.Resolve <IRepository <Empleat> >();
            var entityWithDni = repo.QueryAll().FirstOrDefault(s => s.Dni == dni);

            if (entityWithDni == null)
            {
                output.IsSuccess = false;
                output.Errors.Add($"No existe empled@ con ese DNI {dni}");
            }
            #endregion

            if (output.IsSuccess)
            {
                output.ValidatedResult = dni;
            }
            return(output);
        }
Esempio n. 5
0
        public static ValidationResult <int> ValidateChairNumber(string chairNumberText, Guid currentId = default, bool dublicate = true)
        {
            var output = new ValidationResult <int>()
            {
                IsSuccess = true
            };

            var chairNumber    = 0;
            var isConversionOk = false;

            #region check null or empty
            if (string.IsNullOrEmpty(chairNumberText))
            {
                output.IsSuccess = false;
                output.Errors.Add("el número de la silla no puede estar vacío o nulo");
            }
            #endregion

            #region check format conversion

            isConversionOk = int.TryParse(chairNumberText, out chairNumber);

            if (!isConversionOk)
            {
                output.IsSuccess = false;
                output.Errors.Add($"no se puede convertir {chairNumber} en número");
            }

            #endregion

            #region check if the char is already in use

            if (isConversionOk && dublicate)
            {
                var repoStudents          = DepCon.Resolve <IStudentsRepository>();
                var currentStudentInChair = repoStudents.QueryAll().FirstOrDefault(s => s.ChairNumber == chairNumber);

                if (currentStudentInChair != null)
                {
                    if (currentId == default)
                    {
                        output.IsSuccess = false;
                        output.Errors.Add($"ya hay un alumno {currentStudentInChair.Name} en la silla {chairNumber}");
                    }
                    else if (currentId != default && currentStudentInChair.Id != currentId)
                    {
                        output.IsSuccess = false;
                        output.Errors.Add($"ya hay un alumno {currentStudentInChair.Name} en la silla {chairNumber}");
                    }
                }
            }
            #endregion

            if (output.IsSuccess)
            {
                output.ValidatedResult = chairNumber;
            }

            return(output);
        }
Esempio n. 6
0
        public static ValidationResult <string> ValidateExistSub(string name, Guid currentId = default)
        {
            var output = new ValidationResult <string>()
            {
                IsSuccess = true
            };

            if (string.IsNullOrEmpty(name))
            {
                output.IsSuccess = false;
                output.Errors.Add("No ha introducido el nombre de la asignatura");
            }
            else
            {
                var repo           = DepCon.Resolve <IRepository <Subjects> >();
                var entityWithName = repo.QueryAll().FirstOrDefault(s => s.Name == name);

                if (entityWithName.Name == null)
                {
                    output.IsSuccess = false;
                    output.Errors.Add($"No existe una asignatura con este nombre {name}");
                }
            }

            if (output.IsSuccess)
            {
                output.ValidatedResult = name;
            }

            return(output);
        }
Esempio n. 7
0
        public virtual SaveResult <T> Save <T>() where T : Entity
        {
            var output = new SaveResult <T>();

            CurrentValidation = Validate();

            if (CurrentValidation.IsSuccess)
            {
                var repo = DepCon.Resolve <IRepository <T> >();

                if (this.Id == Guid.Empty)
                {
                    this.Id = Guid.NewGuid();   //Added Jaume 18/01/2020
                    output  = repo.Add(this as T);
                }
                else
                {
                    output = repo.Update(this as T);
                }
            }

            output.Validation = CurrentValidation;

            return(output);
        }
Esempio n. 8
0
        public virtual SaveResult <T> Delete <T>() where T : Entity
        {
            var output = new SaveResult <T>();
            var repo   = DepCon.Resolve <IRepository <T> >();

            repo.Delete(this as T);
            return(output);
        }
        public tRepo GetRepository <tRepo>()
        {
            if (log.IsInfoEnabled)
            {
                log.Info(Consts.ENTERED);
            }

            return(DepCon.GetDependency <tRepo>());
        }
        public ValidationResult <string> ValidateName(Guid studentId, Guid subjectId, Guid currentId = default)
        {
            var output = new ValidationResult <string>()
            {
                IsSuccess = true
            };


            var studentBySubjects = new List <StudentSubject>();

            studentBySubjects = StudentBySubjects(studentId);

            //On Delete
            if (currentId != default)
            {
                output.IsSuccess = true;
            }

            //On Create
            else
            {
                if (studentId == default)
                {
                    output.IsSuccess = false;
                    output.Errors.Add("el Student no puede estar vacío");
                }


                else
                {
                    if (subjectId == default)
                    {
                        output.IsSuccess = false;
                        output.Errors.Add("la Asignatura no puede estar vacío");
                    }


                    else
                    {
                        var repo = DepCon.Resolve <IRepository <StudentSubject> >();

                        if (studentBySubjects != null && studentBySubjects.Any(x => x.SubjectId == subjectId))
                        {
                            output.IsSuccess = false;
                            output.Errors.Add("Ya está asignada esta Asignatura");
                        }
                    }
                }
            }

            return(output);
        }
Esempio n. 11
0
        public static ValidationResult <string> ValidateName(string name, Guid currentId = default)
        {
            var output = new ValidationResult <string>()
            {
                IsSuccess = true
            };

            if (string.IsNullOrEmpty(name))
            {
                output.IsSuccess = false;
                output.Errors.Add("el nombre de la asignatura no puede estar vacío");
            }

            #region check duplication


            var repo           = DepCon.Resolve <ISubjectsRepository>();
            var entityWithName = repo.QueryAll().FirstOrDefault(x => x.Name == name);


            // Aqui llamariamos directamente a memoria:

            //var repo = DepCon.Resolve<IRepository<Subject>>();
            // var entityWithName = repo.QueryAll().FirstOrDefault(x => x.Name == name);


            //var repo = new StudentRepository();
            //var entityWithDni = repo.GetStudentByDni(dni);
            if (entityWithName != null)
            {
                if (currentId == default && entityWithName != null)
                {
                    // on create
                    output.IsSuccess = false;
                    output.Errors.Add("ya existe una asignatura con ese nombre");
                }
                else if (currentId != default && entityWithName.Id != currentId)
                {
                    // on update
                    output.IsSuccess = false;
                    output.Errors.Add("ya existe una asignatura con ese nombre");
                }
            }
            #endregion

            if (output.IsSuccess)
            {
                output.ValidatedResult = name;
            }
            return(output);
        }
Esempio n. 12
0
        public ValidationResult <string> ValidateStudentExam(Guid studentId, Guid examId, Guid currentId = default)
        {
            var output = new ValidationResult <string>()
            {
                IsSuccess = true
            };


            var studentByExams = new List <StudentExam>();

            studentByExams = StudentByExams(studentId);

            //On Delete
            if (currentId != default)
            {
                output.IsSuccess = true;
            }

            //On Create
            else
            {
                if (studentId == default)
                {
                    output.IsSuccess = false;
                    output.Errors.Add("El Student no puede estar vacío");
                }

                else
                {
                    if (examId == default)
                    {
                        output.IsSuccess = false;
                        output.Errors.Add("El Examen no puede estar vacío");
                    }

                    else
                    {
                        var repo = DepCon.Resolve <IRepository <StudentSubject> >();

                        if (studentByExams != null && studentByExams.Any(x => x.ExamId == examId))
                        {
                            output.IsSuccess = false;
                            output.Errors.Add("Ya está registrado este Examen");
                        }
                    }
                }
            }

            return(output);
        }
Esempio n. 13
0
        public static ValidationResult <string> ValidateDni(string dni, Guid currentId = default)
        {
            var output = new ValidationResult <string>()
            {
                IsSuccess = true
            };

            if (string.IsNullOrEmpty(dni))
            {
                output.IsSuccess = false;
                output.Errors.Add("el dni del alumno no puede estar vacío");
            }

            #region check duplication


            var repo          = DepCon.Resolve <IStudentRepository>();
            var entityWithDni = repo.FindByDni(dni);

            //var repo = new Repository<Student>();
            //var entityWithDni = repo.QueryAll().FirstOrDefault(x => x.Dni == dni);

            //var repo = new StudentRepository();
            //var entityWithDni = repo.GetStudentByDni(dni);

            if (entityWithDni != null)
            {
                if (currentId == default && entityWithDni != null)
                {
                    // on create
                    output.IsSuccess = false;
                    output.Errors.Add("ya existe un alumno con ese dni");
                }
                else if (currentId != default && entityWithDni.Id != currentId)
                {
                    // on update
                    output.IsSuccess = false;
                    output.Errors.Add("ya existe un alumno con ese dni");
                }
            }

            #endregion

            if (output.IsSuccess)
            {
                output.ValidatedResult = dni;
            }
            return(output);
        }
Esempio n. 14
0
        public virtual DeleteResult <T> Delete <T>() where T : Entity
        {
            var output = new DeleteResult <T>();

            CurrentValidation = Validate();

            if (CurrentValidation.IsSuccess)
            {
                var repo = DepCon.Resolve <IRepository <T> >();
                output = repo.Delete(this as T);
            }

            output.Validation = CurrentValidation;

            return(output);
        }
Esempio n. 15
0
        public static ValidationResult <string> ValidateDni(string dni, Guid currentId = default)
        {
            var output = new ValidationResult <string>()
            {
                IsSuccess = true
            };

            if (string.IsNullOrEmpty(dni))
            {
                output.IsSuccess = false;
                output.Errors.Add("Debe informar DNI emplead@");
            }
            else if (dni.Length < 9)
            {
                output.IsSuccess = false;
                output.Errors.Add("El DNI de emplead@ no tiene un formato correcto");
            }

            #region check duplication
            var repo          = DepCon.Resolve <IRepository <Empleat> >();
            var entityWithDni = repo.QueryAll().FirstOrDefault(s => s.Dni == dni);

            if (currentId == default && entityWithDni != null)
            {
                // on create
                output.IsSuccess = false;
                output.Errors.Add("Ya existe emplead@ con este DNI");
            }
            else if (currentId != default && entityWithDni != null && entityWithDni.Id != currentId)
            {
                if (entityWithDni.Dni == dni)
                {
                    // on update
                    output.IsSuccess = false;
                    output.Errors.Add("Ya existe emplead@ con este DNI");
                }
            }
            #endregion

            if (output.IsSuccess)
            {
                output.ValidatedResult = dni;
            }

            return(output);
        }
Esempio n. 16
0
        public static ValidationResult <int> ValidateChairNumber(string chairNumberText, string namesubject, string dniStudent)
        {
            var output = new ValidationResult <int>()
            {
                IsSuccess = true
            };

            var chairNumber    = 0;
            var isConversionOk = false;

            if (string.IsNullOrEmpty(chairNumberText))
            {
                output.IsSuccess = false;
                output.Errors.Add("Debe informar el número de silla");
            }
            else
            {
                // check format conversion
                isConversionOk = int.TryParse(chairNumberText, out chairNumber);

                if (!isConversionOk)
                {
                    output.IsSuccess = false;
                    output.Errors.Add($"No se puede convertir {chairNumber} en número");
                }
                else
                {
                    // check if the char is already in use
                    var repo             = DepCon.Resolve <IRepository <Courses> >();
                    var entityWithNumber = repo.QueryAll().FirstOrDefault(s => s.NameSubject == namesubject && s.ChairNumber == chairNumber);

                    if (entityWithNumber != null && entityWithNumber.DniStudent != dniStudent)
                    {
                        output.IsSuccess = false;
                        output.Errors.Add($"Ya existe un alumno en la silla {chairNumber}");
                    }
                }
            }

            if (output.IsSuccess)
            {
                output.ValidatedResult = chairNumber;
            }

            return(output);
        }
Esempio n. 17
0
        public static ValidationResult <string> ValidateDni(string dni, Guid currentId = default)
        {
            var output = new ValidationResult <string>()
            {
                IsSuccess = true
            };

            if (string.IsNullOrEmpty(dni))
            {
                output.IsSuccess = false;
                output.Errors.Add("el dni del alumno no puede estar vacío");
            }

            #region check duplication
            var repo = DepCon.Resolve <IRepository <Student> >();

            //var entityWithDni = repo.GetStudentByDni(dni, currentId);  //Jose
            var entityWithDni = repo.QueryAll().FirstOrDefault(s => s.Dni == dni);

            if (currentId == default && entityWithDni != null)
            {
                // on create
                output.IsSuccess = false;
                output.Errors.Add("ya existe un alumno con ese dni");
            }

            else if (currentId != default && entityWithDni != null && entityWithDni.Id != currentId)    //Modificado
            {
                if (entityWithDni.Dni == dni)
                {
                    // on update
                    // Console.WriteLine("Soy Student : Ya existe un alumno con este DNI");  //Meu
                    output.IsSuccess = false;
                    output.Errors.Add("ya existe un alumno con ese dni");
                }
            }
            #endregion

            if (output.IsSuccess)
            {
                output.ValidatedResult = dni;
            }

            return(output);
        }
Esempio n. 18
0
        public static ValidationResult <string> ValidateName(string name, Guid currentId = default)
        {
            var output = new ValidationResult <string>()
            {
                IsSuccess = true
            };

            if (string.IsNullOrEmpty(name))
            {
                output.IsSuccess = false;
                output.Errors.Add("el nombre de la asignatura no puede estar vacío");
            }

            #region check duplication
            var repo = DepCon.Resolve <IRepository <Subject> >();

            var entityWithName = repo.QueryAll().FirstOrDefault(s => s.Name == name);

            if (currentId == default && entityWithName != null)
            {
                // on create
                output.IsSuccess = false;
                output.Errors.Add("ya existe una Asignatura con ese nombre");
                // Console.WriteLine("Soy Subject : Ya existe una Asignatura con este Nombre");
            }
            //else if (currentId != default && entityWithName.Id != currentId)  //Original
            else if (currentId != default && entityWithName != null && entityWithName.Id != currentId)    //Modificado
            {
                if (entityWithName.Name == name)
                {
                    // on update
                    // Console.WriteLine("Soy Subject : Ya existe una Asignatura con este Nombre");
                    output.IsSuccess = false;
                    output.Errors.Add("Ya existe una Asignatura con este Nombre");
                }
            }
            #endregion

            if (output.IsSuccess)
            {
                output.ValidatedResult = name;
            }

            return(output);
        }
Esempio n. 19
0
        public static ValidationResult <string> ValidateEmail(string email, Guid currentId = default)
        {
            var output = new ValidationResult <string>()
            {
                IsSuccess = true
            };

            if (string.IsNullOrEmpty(email))
            {
                output.IsSuccess = false;
                output.Errors.Add("el email del alumno no puede estar vacío");
            }

            #region check duplication
            var repo = DepCon.Resolve <IRepository <Student> >();

            var entityWithEmail = repo.QueryAll().FirstOrDefault(s => s.Email == email);

            if (currentId == default && entityWithEmail != null)
            {
                // on create
                output.IsSuccess = false;
                output.Errors.Add("ya existe un alumno con ese email");
            }

            else if (currentId != default && entityWithEmail != null && entityWithEmail.Id != currentId)    //Modificado
            {
                if (entityWithEmail.Email == email)
                {
                    // on update
                    output.IsSuccess = false;
                    output.Errors.Add("ya existe un alumno con ese email");
                }
            }
            #endregion

            if (output.IsSuccess)
            {
                output.ValidatedResult = email;
            }

            return(output);
        }
Esempio n. 20
0
        public virtual SaveValidation <T> Save <T>() where T : Entity
        {
            var output = new SaveValidation <T>();

            CurrentValidation = Validate();

            if (CurrentValidation.ValidationSuccesful)
            {
                var repo = DepCon.Resolve <IRepository <T> >();

                if (this.Id == Guid.Empty)
                {
                    output = repo.Add(this as T);
                }
                else
                {
                    output = repo.Update(this as T);
                }
            }

            output.Validation = CurrentValidation;

            return(output);
        }