public async Task <IActionResult> PutAutoCategory([FromRoute] int id, [FromBody] AutoCategory autoCategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != autoCategory.Id) { return(BadRequest()); } _context.Entry(autoCategory).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AutoCategoryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostAutoCategory([FromBody] AutoCategory autoCategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.AutoCategories.Add(autoCategory); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAutoCategory", new { id = autoCategory.Id }, autoCategory)); }
private void ReadyButton_Click(object sender, EventArgs e) { if (NameTextBox.TextLength != 0 && CodeTextBox.TextLength != 0) { AutoCategory newCategory = new AutoCategory(NameTextBox.Text, CodeTextBox.Text); AutoCategoryListService.CategoryRegistration(newCategory); MessageBox.Show("Регистрация новой категории автомобиля успешно завершена", "", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { if (NameTextBox.TextLength == 0) { NameTextBox.BackColor = Color.IndianRed; } if (CodeTextBox.TextLength == 0) { CodeTextBox.BackColor = Color.IndianRed; } } }
public static void CategoryRegistration(AutoCategory newCategory) { AutoCategoryListStorage.Categories.Add(newCategory); }