Exemple #1
0
        public async Task <Response> Insert(Student student)
        {
            Response response = Validate(student);

            if (response.Success)
            {
                student.Cpf.RemoveMaskCPF();
                student.Phonenumber.RemoveMaskPhoneNumber();

                do
                {
                    student.Register = _generateRegister.GenerateRandonRegister();
                } while (!IsUniqueRegister(student.Register).Result.Success);


                try
                {
                    using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                    {
                        await dataBase.Students.AddAsync(student);

                        await dataBase.SaveChangesAsync();

                        ResponseMessage.CreateSuccessResponse();
                    }
                }
                catch (Exception ex)
                {
                    return(ResponseMessage.CreateErrorResponse(ex));
                }
            }
            return(response);
        }
Exemple #2
0
        public async Task <Response> Insert(Company company)
        {
            Response response = Validate(company);

            if (response.Success)
            {
                company.CPNJ   = company.CPNJ.RemoveMask();
                company.Active = true;
                try
                {
                    using (KnowledgeTestDB dataBase = new KnowledgeTestDB())
                    {
                        dataBase.Companies.Add(company);
                        await dataBase.SaveChangesAsync();

                        return(ResponseMessage.CreateSuccessResponse());
                    }
                }
                catch (Exception ex)
                {
                    return(ResponseMessage.CreateErrorResponse(ex));
                }
            }
            return(ResponseMessage.CreateErrorResponse(response.Exception));
        }
Exemple #3
0
        public async Task <Response> Insert(Administrator administrator)
        {
            Response response = Validate(administrator);

            if (response.Success)
            {
                administrator.Cpf.RemoveMaskCPF();
                administrator.Phonenumber.RemoveMaskPhoneNumber();
                administrator.Passcode = EncryptPassword(administrator.Passcode);
                try
                {
                    using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                    {
                        await dataBase.Administrators.AddAsync(administrator);

                        await dataBase.SaveChangesAsync();

                        ResponseMessage.CreateSuccessResponse();
                    }
                }
                catch (Exception ex)
                {
                    return(ResponseMessage.CreateErrorResponse(ex));
                }
            }
            return(response);
        }
Exemple #4
0
        public async Task <SingleResponse <Subject> > ChangeStatus(int id)
        {
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    Subject subject = dataBase.Subjects.Find(id);
                    if (subject.Active == false)
                    {
                        subject.Active = true;
                    }
                    else
                    {
                        subject.Active = false;
                    }
                    await dataBase.SaveChangesAsync();

                    return(ResponseMessage.CreateSingleSuccessResponse <Subject>(subject));
                }
            }
            catch (Exception ex)
            {
                ResponseMessage.CreateErrorResponse(ex);
                return(ResponseMessage.CreateNotFoundData <Subject>());
            }
        }
Exemple #5
0
        public async Task <SingleResponse <Teacher> > ChangeStatus(int id)
        {
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    Teacher teacher = dataBase.Teachers.Find(id);
                    if (teacher.Active == false)
                    {
                        teacher.Active = true;
                    }
                    else
                    {
                        teacher.Active = false;
                    }
                    await dataBase.SaveChangesAsync();

                    return(ResponseMessage.CreateSingleSuccessResponse <Teacher>(teacher));
                }
            }
            catch (Exception ex)
            {
                ResponseMessage.CreateErrorResponse(ex);
                return(ResponseMessage.CreateNotFoundData <Teacher>());
            }
        }
Exemple #6
0
        public async Task <Response> Insert(Subject subject)
        {
            Response response = Validate(subject);

            if (response.Success)
            {
                subject.SubjectName = subject.SubjectName.ToUpper();

                try
                {
                    using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                    {
                        Subject sub = await dataBase.Subjects.FirstOrDefaultAsync(m => m.SubjectName == subject.SubjectName);

                        if (sub != null)
                        {
                            return(ResponseMessage.CreateDuplicateErrorResponse());
                        }
                        dataBase.Subjects.Add(subject);
                        await dataBase.SaveChangesAsync();

                        return(ResponseMessage.CreateSuccessResponse());
                    }
                }
                catch (Exception ex)
                {
                    return(ResponseMessage.CreateErrorResponse(ex));
                }
            }
            return(response);
        }
Exemple #7
0
        public async Task <Response> Insert(Teacher teacher)
        {
            Response response = Validate(teacher);

            if (response.Success)
            {
                teacher.Cpf.RemoveMaskCPF();
                teacher.Phonenumber.RemoveMaskPhoneNumber();

                try
                {
                    using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                    {
                        await dataBase.Teachers.AddAsync(teacher);

                        await dataBase.SaveChangesAsync();

                        ResponseMessage.CreateSuccessResponse();
                    }
                }
                catch (Exception ex)
                {
                    return(ResponseMessage.CreateErrorResponse(ex));
                }
            }
            return(response);
        }
Exemple #8
0
        public async Task <Response> Insert(Class clasS)
        {
            Response response = Validate(clasS);

            if (response.Success)
            {
                clasS.ClassName = clasS.ClassName.ToUpper();
                try
                {
                    using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                    {
                        Class @class = await dataBase.Classes.FirstOrDefaultAsync(m => m.ClassName == clasS.ClassName);

                        if (@class != null)
                        {
                            return(ResponseMessage.CreateDuplicateErrorResponse());
                        }
                        dataBase.Classes.Add(clasS);
                        await dataBase.SaveChangesAsync();

                        ResponseMessage.CreateSuccessResponse();
                    }
                }
                catch (Exception ex)
                {
                    return(ResponseMessage.CreateErrorResponse(ex));
                }
            }
            return(response);
        }
Exemple #9
0
        public async Task <Response> InsertAllGeneratedLessons(List <Lesson> lessons)
        {
            try
            {
                using (BiometricPresenceDB db = new BiometricPresenceDB())
                {
                    db.Lessons.AddRange(lessons);

                    foreach (Lesson item in lessons)
                    {
                        item.Presences = new List <Presence>();
                        Class turma = await db.Classes.Include(c => c.Students).FirstOrDefaultAsync(i => i.ID == item.ClassID);

                        foreach (Student student in turma.Students.ToList())
                        {
                            item.Presences.Add(new Presence()
                            {
                                Lesson     = item,
                                StudentID  = student.ID,
                                Attendance = false,
                            });
                        }
                    }

                    await db.SaveChangesAsync();

                    return(ResponseMessage.CreateSuccessResponse());
                }
            }
            catch (Exception ex)
            {
                return(ResponseMessage.CreateErrorResponse(ex));
            }
        }
Exemple #10
0
        public async Task <QueryResponse <Class> > GetAll()
        {
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    List <Class> classes = await dataBase.Classes.ToListAsync();

                    return(ResponseMessage.CreateQuerySuccessResponse <Class>(classes));
                }
            }
            catch (Exception ex)
            {
                QueryResponse <Class> clasS = (QueryResponse <Class>)ResponseMessage.CreateErrorResponse(ex);
                return(clasS);
            }
        }
Exemple #11
0
        public async Task <QueryResponse <Student> > GetAll()
        {
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    List <Student> students = await dataBase.Students.ToListAsync();

                    return(ResponseMessage.CreateQuerySuccessResponse <Student>(students));
                }
            }
            catch (Exception ex)
            {
                QueryResponse <Student> student = (QueryResponse <Student>)ResponseMessage.CreateErrorResponse(ex);
                return(student);
            }
        }
Exemple #12
0
        public async Task <QueryResponse <Lesson> > GetAll()
        {
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    List <Lesson> lessons = await dataBase.Lessons.ToListAsync();

                    return(ResponseMessage.CreateQuerySuccessResponse <Lesson>(lessons));
                }
            }
            catch (Exception ex)
            {
                QueryResponse <Lesson> lesson = (QueryResponse <Lesson>)ResponseMessage.CreateErrorResponse(ex);
                return(lesson);
            }
        }
Exemple #13
0
        public async Task <QueryResponse <Teacher> > GetAll()
        {
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    List <Teacher> teachers = await dataBase.Teachers.ToListAsync();

                    return(ResponseMessage.CreateQuerySuccessResponse <Teacher>(teachers));
                }
            }
            catch (Exception ex)
            {
                QueryResponse <Teacher> teacher = (QueryResponse <Teacher>)ResponseMessage.CreateErrorResponse(ex);
                return(teacher);
            }
        }
Exemple #14
0
        public async Task <QueryResponse <Subject> > GetAll()
        {
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    List <Subject> subjects = await dataBase.Subjects.Include(c => c.Teachers).ToListAsync();

                    return(ResponseMessage.CreateQuerySuccessResponse <Subject>(subjects));
                }
            }
            catch (Exception ex)
            {
                QueryResponse <Subject> subject = (QueryResponse <Subject>)ResponseMessage.CreateErrorResponse(ex);
                return(subject);
            }
        }
Exemple #15
0
 public async Task <Response> Delete(int id)
 {
     try
     {
         Company company = new Company();
         company.ID = id;
         using (KnowledgeTestDB dataBase = new KnowledgeTestDB())
         {
             dataBase.Entry(company).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
             await dataBase.SaveChangesAsync();
         }
         return(ResponseMessage.CreateSuccessResponse());
     }
     catch (Exception ex)
     {
         return(ResponseMessage.CreateErrorResponse(ex));
     }
 }
Exemple #16
0
        public async Task <SingleResponse <Teacher> > GetByID(int id)
        {
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    Teacher teacher = await dataBase.Teachers.FirstOrDefaultAsync(p => p.ID == id);

                    if (teacher == null)
                    {
                        return(ResponseMessage.CreateNotFoundData <Teacher>());
                    }
                    return(ResponseMessage.CreateSingleSuccessResponse <Teacher>(teacher));
                }
            }
            catch (Exception ex)
            {
                SingleResponse <Teacher> teacher = (SingleResponse <Teacher>)ResponseMessage.CreateErrorResponse(ex);
                return(teacher);
            }
        }
Exemple #17
0
        public async Task <SingleResponse <Lesson> > GetByID(int id)
        {
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    Lesson lesson = await dataBase.Lessons.FirstOrDefaultAsync(p => p.ID == id);

                    if (lesson == null)
                    {
                        return(ResponseMessage.CreateNotFoundData <Lesson>());
                    }
                    return(ResponseMessage.CreateSingleSuccessResponse <Lesson>(lesson));
                }
            }
            catch (Exception ex)
            {
                SingleResponse <Lesson> lesson = (SingleResponse <Lesson>)ResponseMessage.CreateErrorResponse(ex);
                return(lesson);
            }
        }
Exemple #18
0
        public async Task <SingleResponse <Subject> > GetByID(int id)
        {
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    Subject subject = await dataBase.Subjects.FirstOrDefaultAsync(p => p.ID == id);

                    if (subject == null)
                    {
                        return(ResponseMessage.CreateNotFoundData <Subject>());
                    }
                    return(ResponseMessage.CreateSingleSuccessResponse <Subject>(subject));
                }
            }
            catch (Exception ex)
            {
                SingleResponse <Subject> subject = (SingleResponse <Subject>)ResponseMessage.CreateErrorResponse(ex);
                return(subject);
            }
        }
Exemple #19
0
        public async Task <SingleResponse <Class> > GetByID(int id)
        {
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    Class clasS = await dataBase.Classes.FirstOrDefaultAsync(p => p.ID == id);

                    if (clasS == null)
                    {
                        return(ResponseMessage.CreateNotFoundData <Class>());
                    }
                    return(ResponseMessage.CreateSingleSuccessResponse <Class>(clasS));
                }
            }
            catch (Exception ex)
            {
                SingleResponse <Class> clasS = (SingleResponse <Class>)ResponseMessage.CreateErrorResponse(ex);
                return(clasS);
            }
        }
Exemple #20
0
        public async Task <SingleResponse <Student> > IsUniqueRegister(string register)
        {
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    Student student = await dataBase.Students.FirstOrDefaultAsync(p => p.Register == register);

                    if (student == null)
                    {
                        return(ResponseMessage.CreateSingleSuccessResponse <Student>(student));
                    }
                    return(ResponseMessage.CreateNotFoundData <Student>());
                }
            }
            catch (Exception ex)
            {
                SingleResponse <Student> student = (SingleResponse <Student>)ResponseMessage.CreateErrorResponse(ex);
                return(student);
            }
        }
Exemple #21
0
        public async Task <Response> Update(Teacher teacher)
        {
            Response validationResponse = Validate(teacher);

            if (!validationResponse.Success)
            {
                return(validationResponse);
            }
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    dataBase.Entry(teacher).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    await dataBase.SaveChangesAsync();
                }
                return(ResponseMessage.CreateSuccessResponse());
            }
            catch (Exception ex)
            {
                return(ResponseMessage.CreateErrorResponse(ex));
            }
        }
Exemple #22
0
        public async Task <Response> Update(Company company)
        {
            Response Response = Validate(company);

            if (Response.Success)
            {
                try
                {
                    using (KnowledgeTestDB dataBase = new KnowledgeTestDB())
                    {
                        dataBase.Entry(company).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                        await dataBase.SaveChangesAsync();
                    }
                    return(ResponseMessage.CreateSuccessResponse());
                }
                catch (Exception ex)
                {
                    return(ResponseMessage.CreateErrorResponse(ex));
                }
            }
            return(ResponseMessage.CreateErrorResponse(Response.Exception));
        }
Exemple #23
0
        public async Task <SingleResponse <Student> > GetStudentByRegister(string register, string passcode)
        {
            try
            {
                passcode = passcode.EncryptPassword();

                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    Student student = await dataBase.Students.FirstOrDefaultAsync(c => c.Register == register && c.Passcode == passcode);

                    if (student == null)
                    {
                        return(ResponseMessage.CreateNotFoundData <Student>());
                    }
                    //Precisa de cookies
                    return(ResponseMessage.CreateSingleSuccessResponse <Student>(student));
                }
            }
            catch (Exception ex)
            {
                SingleResponse <Student> student = (SingleResponse <Student>)ResponseMessage.CreateErrorResponse(ex);
                return(student);
            }
        }
Exemple #24
0
        public async Task <SingleResponse <Teacher> > GetTeacherByEmail(string email, string passcode)
        {
            try
            {
                passcode = passcode.EncryptPassword();

                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    Teacher teacher = await dataBase.Teachers.FirstOrDefaultAsync(c => c.Email == email && c.Passcode == passcode);

                    if (teacher == null)
                    {
                        return(ResponseMessage.CreateNotFoundData <Teacher>());
                    }
                    //Precisa de cookies
                    return(ResponseMessage.CreateSingleSuccessResponse <Teacher>(teacher));
                }
            }
            catch (Exception ex)
            {
                SingleResponse <Teacher> teacher = (SingleResponse <Teacher>)ResponseMessage.CreateErrorResponse(ex);
                return(teacher);
            }
        }
        public async Task <Response> Insert(Supplier supplier)
        {
            Response response = Validate(supplier);

            if (response.Success)
            {
                supplier.CNPJ_CPF         = supplier.CNPJ_CPF.RemoveMask();
                supplier.Telephone        = supplier.Telephone.RemoveMaskPhoneNumber();
                supplier.DateRegistration = DateTime.Now;
                supplier.Active           = true;
                if (!string.IsNullOrWhiteSpace(supplier.Telephone2))
                {
                    supplier.Telephone2.RemoveMaskPhoneNumber();
                }
                if (supplier.CNPJ_CPF.Length == 11)
                {
                    supplier.RG = supplier.RG.RemoveMask();
                }
                try
                {
                    using (KnowledgeTestDB dataBase = new KnowledgeTestDB())
                    {
                        dataBase.Companies.AttachRange(supplier.Companies);
                        dataBase.Suppliers.Add(supplier);
                        await dataBase.SaveChangesAsync();

                        return(ResponseMessage.CreateSuccessResponse());
                    }
                }
                catch (Exception ex)
                {
                    return(ResponseMessage.CreateErrorResponse(ex));
                }
            }
            return(ResponseMessage.CreateErrorResponse(response.Exception));
        }
Exemple #26
0
        public async Task <Response> Insert(Class clasS)
        {
            Response response = Validate(clasS);

            if (response.Success)
            {
                try
                {
                    using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                    {
                        await dataBase.Classes.AddAsync(clasS);

                        await dataBase.SaveChangesAsync();

                        ResponseMessage.CreateSuccessResponse();
                    }
                }
                catch (Exception ex)
                {
                    return(ResponseMessage.CreateErrorResponse(ex));
                }
            }
            return(response);
        }
Exemple #27
0
        public async Task <SingleResponse <Administrator> > GetAdmByEmail(string email, string passcode)
        {
            try
            {
                passcode = EncryptPassword(passcode);

                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    Administrator administrator = await dataBase.Administrators.FirstOrDefaultAsync(c => c.Email == email && c.Passcode == passcode);

                    if (administrator == null)
                    {
                        return(ResponseMessage.CreateNotFoundData <Administrator>());
                    }
                    //Precisa de cookies
                    //SystemParameters.EmployeeName = response.Data.Name;
                    //SystemParameters.EmployeeADM = response.Data.IsAdm;
                    return(ResponseMessage.CreateSingleSuccessResponse <Administrator>(administrator));
                }
            }
            catch (Exception ex)
            {
                SingleResponse <Administrator> administrator = (SingleResponse <Administrator>)ResponseMessage.CreateErrorResponse(ex);
                return(administrator);
            }
        }
Exemple #28
0
        public async Task <SingleResponse <Administrator> > GetByID(int id)
        {
            try
            {
                using (BiometricPresenceDB dataBase = new BiometricPresenceDB())
                {
                    Administrator administrator = await dataBase.Administrators.FirstOrDefaultAsync(p => p.Id == id);

                    if (administrator == null)
                    {
                        return(ResponseMessage.CreateNotFoundData <Administrator>());
                    }
                    return(ResponseMessage.CreateSingleSuccessResponse <Administrator>(administrator));
                }
            }
            catch (Exception ex)
            {
                SingleResponse <Administrator> administrator = (SingleResponse <Administrator>)ResponseMessage.CreateErrorResponse(ex);
                return(administrator);
            }
        }