public IActionResult DeleteConfirmed(int id) { PetDAL petDAL = new PetDAL(); petDAL.DeletePet(id); return(RedirectToAction("Index")); }
public static List <PetView> GetPets(Guid userId) { PetDAL petHandler = new PetDAL(); List <PetView> petList = new List <PetView>(); List <Pet> pets = petHandler.GetList(); pets = pets.Where(p => p.userId == userId).ToList(); foreach (var pet in pets) { int age = DateTime.Today.Year - (pet.birthDate != null ? pet.birthDate.Value.Year : DateTime.Today.Year); petList.Add(new PetView { Name = pet.name.Trim(), BirthDate = pet.birthDate != null ? pet.birthDate.Value : DateTime.Today, Age = age, Description = pet.description.Trim(), Breed = pet.breed.Trim(), SpecieName = pet.specie.Trim(), Specie = GetSpecie(pet.specie), ImageSrc = string.Format("pets/{0}.jpg", pet.name.Trim()), }); } return(petList); }
public static PetView GetPet(Guid id) { PetDAL petHandler = new PetDAL(); List <PetView> petList = new List <PetView>(); List <Pet> pets = petHandler.GetList(); Pet pet = pets.Where(u => u.id.Equals(id)).FirstOrDefault(); int age = DateTime.Today.Year - (pet.birthDate != null ? pet.birthDate.Value.Year : DateTime.Today.Year); if (pet != null) { return(new PetView { Name = pet.name.Trim(), BirthDate = pet.birthDate != null ? pet.birthDate.Value : DateTime.Today, Age = age, Description = pet.description.Trim(), Breed = pet.breed.Trim(), SpecieName = pet.specie.Trim(), Specie = GetSpecie(pet.specie), ImageSrc = string.Format("pets/{0}.jpg", pet.name.Trim()), }); } else { return(null); } }
public IActionResult Index() { List <Pet> listaPets = new List <Pet>(); PetDAL petDAL = new PetDAL(); listaPets = petDAL.ListarPets(); return(View(listaPets)); }
public IActionResult Edit([Bind] Pet pet) { if (ModelState.IsValid) { PetDAL petDAL = new PetDAL(); petDAL.UpdatePet(pet); return(RedirectToAction("Index")); } return(View(pet)); }
public IActionResult Delete(int id) { PetDAL petDAL = new PetDAL(); Pet pet = petDAL.ObterPet(id); if (pet == null) { return(NotFound()); } return(View(pet)); }
public static void SavePet(PetView petToSave) { PetDAL petHandler = new PetDAL(); Pet pet = new Pet { name = petToSave.Name, birthDate = petToSave.BirthDate, breed = petToSave.Breed, description = petToSave.Description, specie = petToSave.SpecieName, createdDate = DateTime.Now, createdBy = Constant.ADMIN_EMAIL, userId = new Guid(petToSave.UserId), }; petHandler.Post(pet); }
public static List <RecordView> GetRecords(string name) { List <RecordView> recordViews = new List <RecordView>(); RecordDAL recordHandler = new RecordDAL(); PetDAL petHandler = new PetDAL(); List <Record> records = recordHandler.GetList(); List <Pet> petList = petHandler.GetList(); Pet pet = petList.Where(p => p.name.Trim() == name).FirstOrDefault(); if (pet != null && !string.IsNullOrEmpty(pet.name)) { records = records.Where(r => r.petId == pet.id).ToList(); foreach (Record record in records) { RecordView recordView = new RecordView() { Id = record.id.ToString(), IsVaccine = record.isVaccine.Value, Name = record.recordNumber == null ? "" : record.recordNumber.Trim(), Notes = record.notes == null ? "" : record.notes.Trim(), RecordNumber = record.recordNumber.Trim(), Status = record.status == null ? "" : record.status.Trim(), Tags = record.tags != null?record.tags.Split(',').ToList() : new List <string>(), Type = record.type == null ? "" : record.type.Trim(), }; if (record.isVaccine.Value) { VaccineDAL vaccineHandler = new VaccineDAL(); List <Vaccine> vaccines = vaccineHandler.GetList(); vaccines = vaccines.Where(v => v.id == record.vaccineId).ToList(); List <VaccineView> vaccineViews = new List <VaccineView>(); foreach (var vaccine in vaccines) { vaccineViews.Add(new VaccineView { Cost = vaccine.cost.ToString(), Description = vaccine.description == null ? "" : vaccine.description.Trim(), Disease = vaccine.disease == null ? "" : vaccine.disease.Trim(), Id = vaccine.id.ToString(), Living = vaccine.living == true ? "Is living" : "Not living", Name = vaccine.name == null ? "" : vaccine.name.Trim(), Preparation = vaccine.preparation == null ? "" : vaccine.preparation.Trim(), Type = vaccine.type == null ? "" : vaccine.type.Trim(), }); } recordView.Vaccines = vaccineViews; } recordView.Tags = recordView.Tags.Select(s => s.Trim()).ToList(); recordViews.Add(recordView); } } if (recordViews.Count >= 1) { return(recordViews); } else { return(null); } }