/// <summary> /// Создание вида животного /// </summary> /// <param name="name_kind">Название вида</param> /// <param name="name_famaly">Название семейства</param> /// <param name="number_of_animals">Численность</param> /// <param name="continent">Континент</param> public KindOfAnimalController(string name_kind, string name_famaly, int number_of_animals, string continent) { #region Проверка данных if (string.IsNullOrWhiteSpace(name_kind)) { throw new ArgumentNullException("Имя вида не может быть пустым или null", nameof(name_kind)); } if (string.IsNullOrWhiteSpace(name_famaly)) { throw new ArgumentNullException("Имя семейства не может быть пустым или null", nameof(name_famaly)); } if (number_of_animals < 0) { throw new ArgumentException("Численность животных не может быть отрицательной или null", nameof(number_of_animals)); } if (string.IsNullOrWhiteSpace(continent)) { throw new ArgumentNullException("Имя континента не может быть пустым или null", nameof(continent)); } #endregion AnimalFamily animalfamyly = new AnimalFamily(name_famaly, number_of_animals); KindOfAnimal = new KindOfAnimal(name_kind, animalfamyly, continent); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Kind")] KindOfAnimal kindOfAnimal) { if (id != kindOfAnimal.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(kindOfAnimal); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!KindOfAnimalExists(kindOfAnimal.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(kindOfAnimal)); }
public async Task <IActionResult> Create([Bind("Id,Kind")] KindOfAnimal kindOfAnimal) { if (ModelState.IsValid) { _context.Add(kindOfAnimal); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(kindOfAnimal)); }
private void btnUpdate_Click(object sender, EventArgs e) { try { if (cbxType.SelectedIndex == 0) { int id = Convert.ToInt32(dgwOtherThings.CurrentRow.Cells[0].Value); _phoneType = _wrt.PhoneTypes.FirstOrDefault(p => p.Id == id); _phoneType.Name = tbxName.Text; _wrt.SubmitChanges(); GetPhoneTypesTable(); MessageBox.Show("Entity updated successfully"); tbxName.Text = ""; } else if (cbxType.SelectedIndex == 1) { int id = Convert.ToInt32(dgwOtherThings.CurrentRow.Cells[0].Value); _managementType = _wrt.ManagementTypes.FirstOrDefault(p => p.Id == id); _managementType.Name = tbxName.Text; _wrt.SubmitChanges(); GetManagementTypesTable(); MessageBox.Show("Entity updated successfully"); tbxName.Text = ""; } else if (cbxType.SelectedIndex == 2) { int id = Convert.ToInt32(dgwOtherThings.CurrentRow.Cells[0].Value); _kindOfAnimal = _wrt.KindOfAnimals.FirstOrDefault(p => p.Id == id); _kindOfAnimal.Name = tbxName.Text; _wrt.SubmitChanges(); GetKindOfAnimalsTable(); MessageBox.Show("Entity updated successfully"); tbxName.Text = ""; } } catch { MessageBox.Show("We got a problem on the system.Try it another time."); } }
/// <summary> /// Конструктор /// </summary> /// <param name="kindOfAnimal">Вид животного</param> /// <param name="kindOfAnimal">Вид животного</param> public SaveKindAnimal(KindOfAnimal kindOfAnimal) { KindOfAnimal = kindOfAnimal; }