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

            if (id != hero.ID)
            {
                return(BadRequest());
            }

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

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

            return(Ok(hero));
        }
Esempio n. 2
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. 6
0
        public async Task <IActionResult> EditToy(ToyPostData toy)
        {
            var toyFromDb = await _context.Toys
                            .Include(p => p.Seller)
                            .FirstOrDefaultAsync(p => p.ID == toy.ID);

            if (toyFromDb == null)
            {
                AddError($"Toy with ID {toy.ID} Doesn't exist");
                return(RedirectToAction("Index", "Home"));
            }

            var toyCategory = await _context.Categories.FirstOrDefaultAsync(c => c.ID == toy.categoryID);

            if (toyCategory == null)
            {
                AddError($"Category with ID {toy.categoryID} Doesn't exist");
                return(RedirectToAction("Index", "Home"));
            }

            if (toyFromDb.Seller.Id != User.GetUserId() &&
                !User.IsAdmin())
            {
                AddError($"Only the seller of the item or an admin can update a toy's details");
                return(RedirectToAction("Index", "Home"));
            }

            toyFromDb.Description = toy.Description;
            toyFromDb.ImageUrl    = toy.ImageUrl;
            toyFromDb.Name        = toy.Name;
            toyFromDb.Price       = toy.Price;
            toyFromDb.Available   = toy.Available;
            toyFromDb.Category    = toyCategory;

            await _context.SaveChangesAsync();

            AddInfo($"Toy {toy.Name} succefully updated");

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 7
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));
        }
Esempio n. 8
0
        private async Task RemoveToyInternal(int toyId)
        {
            var toy = await _context.Toys.FirstOrDefaultAsync(p => p.ID == toyId);

            var currUser = await UserRoles.GetUser(User, _userManager);

            if (toy == null)
            {
                AddError($"No toy with id {toyId} was found");
                return;
            }
            if (toy.Seller != (currUser) && !UserRoles.IsAdmin(User))
            {
                AddError("You cannot remove a toy that is not yours!");
                return;
            }

            //if (toy.Seller != R)

            AddInfo("Toy - " + toy.Name + " - was deleted.");
            _context.Toys.Remove(toy);
            await _context.SaveChangesAsync();
        }
Esempio n. 9
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));
        }