Beispiel #1
0
        public async Task <IActionResult> Create(DtoCurso curso)
        {
            byte[] imagen          = null;
            string extensionImagen = null;

            if (curso.Imagen?.Length > 0)
            {
                using (var memstream = new MemoryStream())
                {
                    curso.Imagen.OpenReadStream().CopyTo(memstream);
                    imagen          = memstream.ToArray();
                    extensionImagen = curso.Imagen.ContentType;
                }
            }

            if (ModelState.IsValid)
            {
                var newDbItem = new Curso
                {
                    CodCurso        = curso.CodCurso,
                    Descripcion     = curso.Descripcion,
                    Imagen          = imagen,
                    ExtensionImagen = extensionImagen,
                    CodCategoria    = curso.CodCategoria,
                    Destacado       = curso.Destacado,
                    Fecha           = curso.Fecha
                };

                _context.Add(newDbItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(curso));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("ID,LastName,FirstMidName,EnrollmentDate")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("CourseID,Title,Credits")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }
Beispiel #4
0
        public async Task <IActionResult> Create([Bind("EnrollmentID,CourseID,StudentID,Grade")] Enrollment enrollment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enrollment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseID"]  = new SelectList(_context.Set <Course>(), "CourseID", "CourseID", enrollment.CourseID);
            ViewData["StudentID"] = new SelectList(_context.Student, "ID", "ID", enrollment.StudentID);
            return(View(enrollment));
        }