public async Task <IActionResult> PutCourse([FromRoute] int id, [FromBody] Course course)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != course.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PutEnrollment(int id, Enrollment enrollment)
        {
            if (id != enrollment.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutTeacher(int id, Teacher teacher)
        {
            if (id != teacher.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("ID,NomeMarca,Linha,Garantia,Nacionalidade,TempoMercado")] Marca marca)
        {
            if (ModelState.IsValid)
            {
                _context.Add(marca);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(marca));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("ID,NomeLivro,Autor,Genero,NPaginas,Prefacio,AnoLivro")] Biblioteca biblioteca)
        {
            if (ModelState.IsValid)
            {
                _context.Add(biblioteca);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(biblioteca));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("ID,NomeCarro,Modelo,Ano,Cor,Combustivel")] Carros carros)
        {
            if (ModelState.IsValid)
            {
                _context.Add(carros);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(carros));
        }
        public async Task <IActionResult> Create([Bind("Id,Title,Credits,Semester,Programme,EducationLevel,FirstTeacherId,SecondTeacherId")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FirstTeacherId"]  = new SelectList(_context.Teacher, "Id", "FullName", course.FirstTeacherId);
            ViewData["SecondTeacherId"] = new SelectList(_context.Teacher, "Id", "FullName", course.SecondTeacherId);
            return(View(course));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create(EnrollmentViewModel model)
        {
            if (ModelState.IsValid)
            {
                string     uniqueFileName = UploadedFile(model);
                Enrollment enrol          = new Enrollment
                {
                    CourseId         = model.CourseId,
                    StudentId        = model.StudentId,
                    Semester         = model.Semester,
                    Year             = model.Year,
                    Grade            = model.Grade,
                    ProjectUrl       = model.ProjectUrl,
                    ExamPoints       = model.ExamPoints,
                    SeminalPoints    = model.SeminalPoints,
                    ProjectPoints    = model.ProjectPoints,
                    AdditionalPoints = model.AdditionalPoints,
                    FinishDate       = model.FinishDate,
                    FileName         = uniqueFileName,
                };
                _context.Add(enrol);
                await _context.SaveChangesAsync();

                ViewData["Courseid"]  = new SelectList(_context.Course, "Id", "Title");
                ViewData["Studentid"] = new SelectList(_context.Student, "Id", "FullName");
                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
        public async Task <IActionResult> Create(TeacherViewModel model)
        {
            if (ModelState.IsValid)
            {
                string  uniqueFileName = UploadedFile(model);
                Teacher teacher        = new Teacher
                {
                    FirstName      = model.FirstName,
                    LastName       = model.LastName,
                    Degree         = model.Degree,
                    AcademicRank   = model.AcademicRank,
                    OfficeNumber   = model.OfficeNumber,
                    HireDate       = model.HireDate,
                    ProfilePicture = uniqueFileName,
                };
                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Create(StudentViewModel model)
        {
            if (ModelState.IsValid)
            {
                string  uniqueFileName = UploadedFile(model);
                Student student        = new Student
                {
                    FirstName       = model.FirstName,
                    LastName        = model.LastName,
                    IndexId         = model.IndexId,
                    EducationLevel  = model.EducationLevel,
                    AcquiredCredits = model.AcquiredCredits,
                    CurrentSemestar = model.CurrentSemestar,
                    EnrollmentDate  = model.EnrollmentDate,
                    ProfilePicture  = uniqueFileName,
                };
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View());
        }