public Petvm MapToModel(Pet entity) { var petVm = new Petvm(); petVm.Vaccines = new List <VaccineVm>(); petVm.Id = entity.Id; petVm.Name = entity.Name; petVm.Dob = entity.DateOfBirth; petVm.UserId = entity.UserId; petVm.AnimalTypeId = entity.AnimalTypeId; if (entity.PetVaccines == null) { return(petVm); } foreach (var item in entity.PetVaccines) { var vaccineVm = new VaccineVm(); vaccineVm.Name = item.Vaccine.Name; vaccineVm.AppliedDate = item.Date; petVm.Vaccines.Add(vaccineVm); } return(petVm); }
public int Create(VaccineVm item) { var ent = _mapper.MaptoEntity(item); _context.Vaccines.Add(ent); _context.SaveChanges(); return(ent.Id); }
public void Update(int id, VaccineVm item) { var ent = _mapper.MaptoEntity(item); var vaccine = _context.Vaccines.Any(x => x.Id == id); if (!vaccine) { return; } ent.Id = id; _context.Vaccines.Update(ent); _context.SaveChanges(); return; }
public IActionResult Update(int id, VaccineVm item) { _service.Update(id, item); return(NoContent()); }
public IActionResult Create(VaccineVm item) { var id = _service.Create(item); return(CreatedAtRoute("GetVaccine", new { id = item.Id }, item)); }