Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("CoachId,Name,Age,Biography")] CoachEditViewModel coach)
        {
            if (id != coach.CoachId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var efCoach = _context.Coaches.Find(coach.CoachId);

                efCoach.Biography = coach.Biography;
                efCoach.Age       = coach.Age;
                efCoach.Name      = coach.Name;

                _context.Update(efCoach);
                await _context.SaveChangesAsync();

                if (this.User.IsInRole("Admin"))
                {
                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(coach));
        }
        public async Task <IActionResult> Edit(CoachEditViewModel coach, IFormFile ava)
        {
            try
            {
                var coachDto = _mapper.Map <CoachEditViewModel, CoachDTO>(coach);
                coachDto.Team = await UpdateTeam(coach.TeamId, coach.Id);

                await _сoachService.UpdateCoach(coachDto, ava, true);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                @TempData["Error"] = ex.Message + "\n\n" + ex.InnerException?.Message;
                return(RedirectToAction("Error", "Home"));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var coach = await _context.Coaches.FindAsync(id);

            if (coach == null)
            {
                return(NotFound());
            }

            var retCoach = new CoachEditViewModel {
                Name      = coach.Name,
                CoachId   = coach.CoachId,
                Age       = coach.Age,
                Biography = coach.Biography
            };

            return(View(retCoach));
        }