Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("ID,Nombre,Imagen")] Pais pais, IFormFile file)
        {
            if (ModelState.IsValid)

            {
                if (file != null && file.Length > 0)
                {
                    try
                    {
                        string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\Banderas",
                                                   Path.GetFileName(file.FileName));
                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await file.CopyToAsync(stream);
                        }
                        pais.Imagen = "/images/Banderas/" + file.FileName;
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Message = "ERROR:" + ex.Message.ToString();
                    }
                }
                else
                {
                    ViewBag.Message = "You have not specified a file.";
                }
                pais.ID = _context.Paises.Max(M => M.ID);
                pais.ID = pais.ID + 1;
                _context.Add(pais);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(pais));
        }
        public async Task <IActionResult> Create([Bind("Id,CourseId,StudentId,Semester,Year,Grade,SeminalUrl,ProjectUrl,ExamPoints,SeminalPoints,ProjectPoints,AdditionalPoints,FinishDate")] Enrollment enrollment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enrollment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseId"]  = new SelectList(_context.Course, "Id", "Title", enrollment.CourseId);
            ViewData["StudentId"] = new SelectList(_context.Student, "Id", "FullName", enrollment.StudentId);
            return(View(enrollment));
        }
        public async Task <IActionResult> Create([Bind("Id,StudentId,FirstName,LastName,EnrollmentDate,AcquiredCredits,CurrentSemester,EducationLevel,ProfileImage")] Student student)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(student);
                student.ProfilePicture = uniqueFileName;
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
        public async Task <IActionResult> Create([Bind("Id,FirstName,LastName,Degree,AcademicRank,OfficeNumber,HireDate,ProfileImage")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(teacher);
                teacher.ProfilePicture = uniqueFileName;
                _context.Add(teacher);
                await _context.SaveChangesAsync();

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

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FirstTeacherId"]  = new SelectList(_context.Set <Teacher>(), "Id", "FullName", course.FirstTeacherId);
            ViewData["SecondTeacherId"] = new SelectList(_context.Set <Teacher>(), "Id", "FullName", course.SecondTeacherId);
            return(View(course));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("ID,PaisID,Nombres,Apellido_p,Apellido_M,Lugar_Nac,Fecha_Nac,Altura,Peso,Club,Foto,Condicion,Fuerza,Velocidad,Reacción,Control_de_Balon,Anotacion,Barrida,Centros,Defensa,Marcaje,Carcateristica1,Carcateristica2")] Jugador jugador, IFormFile file)
        {
            if (ModelState.IsValid)
            {
                if (file != null && file.Length > 0)
                {
                    try
                    {
                        string path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\images\\Jugadores",
                                                   Path.GetFileName(file.FileName));
                        using (var stream = new FileStream(path, FileMode.Create))
                        {
                            await file.CopyToAsync(stream);
                        }
                        jugador.Foto = "/images/Jugadores/" + file.FileName;
                    }
                    catch (Exception ex)
                    {
                        ViewBag.Message = "ERROR:" + ex.Message.ToString();
                    }
                }
                else
                {
                    ViewBag.Message = "You have not specified a file.";
                }

                jugador.ID = _context.Jugadores.Max(M => M.ID);
                jugador.ID = jugador.ID + 1;


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

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PaisID"] = new SelectList(_context.Paises, "ID", "Nombre", jugador.PaisID);
            return(View(jugador));
        }