Ejemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Url,Gender,Culture,Born,Died,Father,Mother,Spouse")] Character character)
        {
            if (id != character.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(character);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CharacterExists(character.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(character));
        }
        public async Task <IActionResult> Edit(int id, [Bind(
                                                            "ID," +
                                                            "Name," +
                                                            "Species," +
                                                            "Gender," +
                                                            "Faction," +
                                                            "Homeworld," +
                                                            "Background," +
                                                            "Class," +
                                                            "PartialClasses," +
                                                            "Strength," +
                                                            "StrengthModifierBonus," +
                                                            "Dexterity," +
                                                            "DexterityModifierBonus," +
                                                            "Constitution," +
                                                            "ConstitutionModifierBonus," +
                                                            "Intelligence," +
                                                            "IntelligenceModifierBonus," +
                                                            "Wisdom," +
                                                            "WisdomModifierBonus," +
                                                            "Charisma" +
                                                            "CharismaModifierBonus,")] Character character)
        {
            if (id != character.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(character);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CharacterExists(character.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(character));
        }
Ejemplo n.º 3
0
        public async Task <ServiceResponse <CharacterReadDto> > UpdateCharacter(CharacterUpdateDto dto)
        {
            ServiceResponse <CharacterReadDto> serviceResponse = new ServiceResponse <CharacterReadDto>();

            try
            {
                Character character = _context.Characters.AsNoTracking().First(c => c.Id == dto.IdForUpdate);
                character = _mapper.Map <CharacterUpdateDto, Character>(dto, character);
                _context.Update(character);
                if (await SaveChanges())
                {
                    serviceResponse.Data = _mapper.Map <CharacterReadDto>(character);
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }

            return(serviceResponse);
        }