コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,Valor,Estoque")] Produto produto)
        {
            if (id != produto.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(produto);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProdutoExists(produto.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(produto));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,Email,Telefone")] Contatos contatos)
        {
            if (id != contatos.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(contatos);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContatosExists(contatos.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(contatos));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Marca,Modelo,AnoLancamento,AnoMontagem,Chassis")] Carro carro)
        {
            if (id != carro.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(carro);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CarroExists(carro.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(carro));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,Nascimento,CPF,RG,Celular,Email")] Cliente cliente)
        {
            if (id != cliente.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(cliente);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClienteExists(cliente.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(cliente));
        }
コード例 #5
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,Nascimento,Email")] Pessoa pessoa)
        {
            if (id != pessoa.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(pessoa);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PessoaExists(pessoa.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(pessoa));
        }
コード例 #6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Descricao,Vencimento,Valor")] Conta conta)
        {
            if (id != conta.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(conta);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ContaExists(conta.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(conta));
        }
コード例 #7
0
        public ActionResult Edit(EditItem editItem)
        {
            var game = _context.Games
                       .Include(g => g.GameModes)
                       .Include(g => g.GameModes).ThenInclude(gm => gm.winCondition)
                       .SingleOrDefault(g => g.ID == editItem.ID);

            if (editItem.Name.Length < 1 || editItem.Name == null)
            {
                return(BadRequest("Name has to be at least 1 letter."));
            }

            else if (editItem.MinPlayerCount == null || editItem.MaxPlayerCount == null)
            {
                return(BadRequest("MinPlayerCount/MaxPlayerCount cannot be empty"));
            }
            else if (editItem.MinPlayerCount > editItem.MaxPlayerCount)
            {
                return(BadRequest("MinPlayerCount has to be smaller than MaxPlayerCount/MaxPlayerCount has to be larger than MinPlayerCount."));
            }
            else
            {
                game.Name           = editItem.Name;
                game.MinPlayerCount = editItem.MinPlayerCount;
                game.MaxPlayerCount = editItem.MaxPlayerCount;
            }

            if (editItem.EditGameModeItems.Count == 0 || editItem.EditGameModeItems == null)
            {
                return(BadRequest("Each game has to have at least one GameMode."));
            }
            else
            {
                for (var i = 0; i < editItem.EditGameModeItems.Count; i++)
                {
                    var gm = game.GameModes.SingleOrDefault(g => g.ID == editItem.EditGameModeItems[i].ID);
                    if (gm != null)
                    {
                        gm.Name         = editItem.EditGameModeItems[i].Name;
                        gm.Description  = editItem.EditGameModeItems[i].Description;
                        gm.winCondition = _context.WinConditions.SingleOrDefault(w => w.ID == editItem.EditGameModeItems[i].WinConditionID);
                        _context.Update(gm);
                    }
                    else if (gm == null)
                    {
                        if (_context.WinConditions.SingleOrDefault(w => w.ID == editItem.EditGameModeItems[i].WinConditionID) == null)
                        {
                            return(BadRequest("Cannot find WinConditionId"));
                        }
                        else
                        {
                            var gamemode = new GameMode
                            {
                                Name         = editItem.EditGameModeItems[i].Name,
                                Description  = editItem.EditGameModeItems[i].Description,
                                winCondition = _context.WinConditions.SingleOrDefault(w => w.ID == editItem.EditGameModeItems[i].WinConditionID)
                            };
                            game.GameModes.Add(gamemode);
                        }
                    }
                }
            }

            var originalGameModeList = _context.GameModes.Where(gm => gm.game.ID == editItem.ID).ToList();
            var deletedGameModes     = originalGameModeList.Where(gm => editItem.EditGameModeItems.All(gm2 => gm2 != null && gm2.ID != gm.ID));

            if (deletedGameModes != null)
            {
                _context.GameModes.RemoveRange(deletedGameModes);
            }
            _context.Update(game);
            _context.SaveChanges();

            return(Ok(
                       new
            {
                message = "Item is posted"
            }));
        }
コード例 #8
0
 public void Update(Product product)
 {
     _context.Update(product);
 }