public async Task <ActionResult> SavePet(Animal animal) { if (ModelState.IsValid) { if (animal.Id.Equals(null)) { await _animalRepository.Insert(animal); } else { await _animalRepository.Update(animal); } await _animalRepository.SaveChangesAsync(); return(RedirectToAction("Details", "Bites", new { biteId = animal.BiteId, Message = Constant.ManageMessageId.SavePetVictimDataSuccess })); } var PetFormViewModel = new AnimalViewModel { Animal = animal, Breeds = _breedRepository.All(), Specieses = _speciesRepository.All(), Employees = _employeeRepository.All(), Vets = _vetRepository.All() }; return(View("PetForm", PetFormViewModel)); }
public void Insert(Animal animal) { if (animal == null) { throw new Exception("O animal não pode ser nulo"); } if (string.IsNullOrEmpty(animal.Name)) { throw new Exception("O animal precisa ter Name"); } animal.DateEntry = DateTime.Now; animalRepository.Insert(animal); }
private void btnCadastrar_Click(object sender, EventArgs e) { if ((txtNome.Text.Trim() == string.Empty) || (txtNomeDoDono.Text.Trim() == string.Empty) || (cbxRaca.Text.Trim() == string.Empty) || (txtTipo.Text.Trim() == string.Empty)) { return; } Animal animal = new Animal(); var animalRepository = new AnimalRepository(); animal.Nome = this.txtNome.Text; animal.NomeDono = this.txtNomeDoDono.Text; animal.Raça = this.cbxRaca.Text; animal.Espécie = this.cbxEspecie.Text; animal.TelefoneTipo = this.txtTipo.Text; animalRepository.Insert(animal); this.dataCadAnimal.DataSource = animalRepository.FindAll(); }
public void InsertAnimals(AnimalView model) { using (var x = new AnimalRepository()) { var animals = new Animal { AnimalId = model.AnimalId, AniCode = model.AniCode, BatchTypeid = model.BatchTypeid, AniColor = model.AniColor, AniFeedingStatus = "FeedLot", AniAge = model.AniAge, AniGender = model.AniGender, AniHealthStatus = "Healthy", AniCurrentCost = model.AniCurrentCost, AniSaleStatus = "Not Ready", AniTotCost = 0, AnimalValue = model.AnimalValue, }; x.Insert(animals); } }