Beispiel #1
0
        public async Task <IActionResult> Create(TeamViewModel teamViewModel)
        {
            if (ModelState.IsValid)
            {
                var path = string.Empty;

                if (teamViewModel.LogoFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(teamViewModel.LogoFile, "Teams");
                }

                var teamEntity = _converterHelper.ToTeamEntity(teamViewModel, path, true);

                _context.Add(teamEntity);
                try
                {
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (Exception ex)
                {
                    if (ex.InnerException.Message.Contains("duplicate"))
                    {
                        ModelState.AddModelError(string.Empty, $"Already exists the team: {teamEntity.Name}.");
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, ex.InnerException.Message);
                    }
                }
            }
            return(View(teamViewModel));
        }
        public async Task <IActionResult> Create(TournamentViewModel model)
        {
            if (ModelState.IsValid)
            {
                string path = string.Empty;

                if (model.LogoFile != null)
                {
                    path = await _imageHelper.UploadImageAsync(model.LogoFile, "Tournaments");
                }

                TournamentEntity tournament = _converterHelper.ToTournamentEntity(model, path, true);
                _dataContex.Add(tournament);
                await _dataContex.SaveChangesAsync();

                RedirectToAction(nameof(Index));
            }
            return(View(model));
        }
Beispiel #3
0
        public IActionResult Create(PersonaViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            var persona = new Persona
            {
                Nombre            = vm.Nombre,
                Apellido          = vm.Apellido,
                Direccion         = vm.Direccion,
                Email             = vm.Email,
                Telefono          = vm.Telefono,
                TipoIdentificador = vm.TipoIdentificador
            };

            _context.Add(persona);

            _context.SaveChanges();


            return(RedirectToAction("Index", "Home"));
        }