public async Task <IActionResult> PutProfesor(int id, Profesor profesor)
        {
            using (var _context = new SchoolDBContext())
            {
                if (id != profesor.Id)
                {
                    return(BadRequest());
                }

                _context.Entry(profesor).State = EntityState.Modified;

                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProfesorExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(NoContent());
            }
        }
Example #2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            using (SchoolDBContext db = new SchoolDBContext())
            {
                infoTable.Visible = true;

                Student stud = new Student();
                stud.FirstName    = txtFName.Text;
                stud.LastName     = txtLName.Text;
                stud.MobileNumber = txtMobile.Text;
                stud.EmailAddress = txtEmail.Text;
                stud.Hobbies      = txtHobbies.Text;
                Classroom classroom = db.Classrooms.Where(c => c.Id.ToString() == Classroom_ddl.SelectedValue).FirstOrDefault();
                stud.Classroom = classroom;
                CultureInfo provider = CultureInfo.InvariantCulture;
                string      format   = "dd/MM/yyyy";
                if (!string.IsNullOrEmpty(txtDob.Text))
                {
                    stud.DateOfBirth = DateTime.ParseExact(txtDob.Text, format, provider);
                }
                db.Students.Add(stud);
                db.SaveChanges();
                lbltable_fName.Text     = stud.FirstName;
                lbltable_lName.Text     = stud.LastName;
                lbltable_email.Text     = stud.EmailAddress;
                lbltable_mobile.Text    = stud.MobileNumber;
                lbltable_hobbies.Text   = stud.Hobbies;
                lbltable_classroom.Text = stud.Classroom.Name;

                string format_display = "dd MMM yyyy";
                lbltable_dob.Text     = stud.DateOfBirth.ToString(format_display, provider);
                CreationMesssage.Text = "The Student Profile has been created successfully.";
            }
        }
Example #3
0
 public async Task <ActionResult <IEnumerable <Trabajo> > > GetTrabajo()
 {
     using (var _context = new SchoolDBContext())
     {
         return(await _context.Trabajo.ToListAsync());
     }
 }
Example #4
0
 private bool TrabajoExists(int id)
 {
     using (var _context = new SchoolDBContext())
     {
         return(_context.Trabajo.Any(e => e.Id == id));
     }
 }
 public Student GetStudent(int id)
 {
     using (var ctx = new SchoolDBContext())
     {
         return(ctx.Students.Include(s => s.Tests).FirstOrDefault(s => s.StudentId == id));
     }
 }
 public async Task <ActionResult <IEnumerable <Estudiante> > > GetEstudiante()
 {
     using (var _context = new SchoolDBContext())
     {
         return(await _context.Estudiante.ToListAsync());
     }
 }
 private bool MateriaExists(int id)
 {
     using (var _context = new SchoolDBContext())
     {
         return(_context.Materia.Any(e => e.Id == id));
     }
 }
Example #8
0
        public static void UpdatingData()
        {
            SchoolDBContext context = new SchoolDBContext();

            try
            {
                var std = context.Student.First <Estudiantes>();
                std.Nombres = "Mabel";
                bool modified = context.SaveChanges() > 0;

                if (modified)
                {
                    Console.WriteLine("Modificado..");
                }
                else
                {
                    Console.WriteLine("No se pudo Modificar");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                context.Dispose();
            }
        }
Example #9
0
        public static void QuerryUsingSql()
        {
            SchoolDBContext    context     = new SchoolDBContext();
            List <Estudiantes> studentList = new List <Estudiantes>();

            try
            {
                studentList = context.Student.FromSqlRaw("Select *from dbo.Students").ToList();
                if (studentList != null)
                {
                    Console.WriteLine(studentList.Find(s => s.Nombres == "Bill").Nombres);
                }
                else
                {
                    Console.WriteLine("No se pudo Encontrar el Estudiante!!");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                context.Dispose();
            }
        }
Example #10
0
        static void Main(string[] args)
        {
            using (SchoolDBContext DB = new SchoolDBContext())
            {
                Console.WriteLine("Enter Your Operation Code");
                Console.WriteLine("1. Insert");
                Console.WriteLine("2. Update");
                Console.WriteLine("3. Delete");
                int operation = Convert.ToInt32(Console.ReadLine());
                switch (operation)
                {
                case 1:
                    Create_Student(DB);
                    break;

                case 2:
                    Update_Student(DB);
                    break;

                case 3:
                    Delete_Student(DB);
                    break;

                default:
                    Console.WriteLine("Wrong Operation");
                    break;
                }
                Console.WriteLine();
                DisplayStudents(DB.Students.ToList());
            }
            Console.ReadKey();
        }
Example #11
0
        public static void DoubleQueryDB()
        {
            SchoolDBContext context = new SchoolDBContext();

            try
            {
                var resultado = context.Courses.Where(c => c.NombreCurso == "Sociales").FirstOrDefault();

                if (resultado != null)
                {
                    Console.WriteLine(resultado.NombreCurso.ToString());
                }
                else
                {
                    Console.WriteLine("No se pudo Encontrar el Curso!!");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                context.Dispose();
            }
        }
Example #12
0
        static void GuardarEstudiantesDB()
        {
            SchoolDBContext context = new SchoolDBContext();

            try
            {
                var auxStudent = new Estudiantes()
                {
                    EstudianteId = 0,
                    Nombres      = "Clarens",
                };
                context.Student.Add(auxStudent);
                bool save = context.SaveChanges() > 0;

                if (save)
                {
                    Console.WriteLine("guadado Correctamente");
                }
                else
                {
                    Console.WriteLine("No Se Pudo Guardar");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                context.Dispose();
            }
        }
 public async Task <IHttpActionResult> TeachersList()
 {
     using (SchoolDBContext context = new SchoolDBContext())
     {
         return(Json(await context.Teachers.ToListAsync()));
     }
 }
 private bool EstudianteExists(int id)
 {
     using (var _context = new SchoolDBContext())
     {
         return(_context.Estudiante.Any(e => e.Id == id));
     }
 }
 private bool ProfesorExists(int id)
 {
     using (var _context = new SchoolDBContext())
     {
         return(_context.Profesor.Any(e => e.Id == id));
     }
 }
 public async Task <ActionResult <IEnumerable <Profesor> > > GetProfesor()
 {
     using (var _context = new SchoolDBContext())
     {
         return(await _context.Profesor.ToListAsync());
     }
 }
 public async Task <ActionResult <IEnumerable <Materia> > > GetMateria()
 {
     using (var _context = new SchoolDBContext())
     {
         return(await _context.Materia.ToListAsync());
     }
 }
Example #18
0
        public static void DeletingData()
        {
            SchoolDBContext context = new SchoolDBContext();

            try
            {
                var std = context.Student.First <Estudiantes>();
                context.Student.Remove(std);
                bool deleted = context.SaveChanges() > 0;

                if (deleted)
                {
                    Console.WriteLine("Ha Sido Eliminado");
                }
                else
                {
                    Console.WriteLine("No se Pudo Eliminar Error");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                context.Dispose();
            }
        }
Example #19
0
        public static void GuardarCurso()
        {
            SchoolDBContext context = new SchoolDBContext();

            try
            {
                var auxCourse = new Cursos()
                {
                    CursoId     = 0,
                    NombreCurso = "Sociales"
                };
                context.Courses.Add(auxCourse);
                bool save = context.SaveChanges() > 0;

                if (save)
                {
                    Console.WriteLine("Guardado !!");
                }
                else
                {
                    Console.WriteLine("No se pudo Guardar");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                context.Dispose();
            }
        }
Example #20
0
 public GradesController(SchoolDBContext schoolDBContext,
                         IMasterService masterService,
                         IGradeService gradeService)
 {
     _schoolDBContext = schoolDBContext;
     _masterService   = masterService;
     _gradeService    = gradeService;
 }
 public void AddTest([FromBody] Test test)
 {
     using (var ctx = new SchoolDBContext())
     {
         ctx.Tests.Add(test);
         ctx.SaveChanges();
     }
 }
Example #22
0
 public SemestersController(SchoolDBContext schoolDBContext,
                            IMasterService masterService,
                            ISemesterService semesterService)
 {
     _schoolDBContext = schoolDBContext;
     _masterService   = masterService;
     _semesterService = semesterService;
 }
 public void AddStudent([FromBody] Student student)
 {
     using (var ctx = new SchoolDBContext())
     {
         ctx.Students.Add(student);
         ctx.SaveChanges();
     }
 }
 // [Route("/GetStudents")]
 public IEnumerable <Student> GetStudents()
 {
     using (var ctx = new SchoolDBContext())
     {
         return(ctx.Students.ToList());
     }
     //return new string[] { "value1", "value2" };
 }
Example #25
0
 public async Task <IHttpActionResult> GetStudentsByTeacher(int Id)
 {
     using (SchoolDBContext context = new SchoolDBContext())
     {
         var StudentTeacher = (context.Students
                               .Where(s => s.TeacherFK == Id));
         return(Json(await StudentTeacher.ToListAsync()));
     }
 }
 public void DeleteStudent([FromBody] int id)
 {
     using (var ctx = new SchoolDBContext())
     {
         var student = ctx.Students.FirstOrDefault(s => s.StudentId == id);
         ctx.Entry(student).State = EntityState.Deleted;
         ctx.SaveChanges();
     }
 }
 public void EditStudent([FromBody] Student student)
 {
     using (var ctx = new SchoolDBContext())
     {
         ctx.Students.Attach(student);
         ctx.Entry(student).State = EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Example #28
0
        public void CreateSchoolDB()
        {
            SchoolDBContext conn = new SchoolDBContext();

            conn.Student_Detail.Add(new Student_Details {
                StudentName = "Test", Address = "some address", Course = "some course"
            });
            conn.SaveChanges();
        }
 public void EditTest([FromBody] Test test)
 {
     using (var ctx = new SchoolDBContext())
     {
         ctx.Tests.Attach(test);
         ctx.Entry(test).State = EntityState.Modified;
         ctx.SaveChanges();
     }
 }
Example #30
0
 public YearsController(IUnitOfWork <SchoolDBContext> unitOfWork,
                        SchoolDBContext schoolDBContext,
                        IMasterService masterService,
                        IYearService yearService)
 {
     _unitOfWork      = unitOfWork;
     _schoolDBContext = schoolDBContext;
     _masterService   = masterService;
     _yearService     = yearService;
 }