public IActionResult AddEditAnimal(int?id) { AnimalVM model = new AnimalVM(); if (id.HasValue) { AnimalRegistration feed = _repo.AnimalRegistration.GetById(id.Value); if (feed != null) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <AnimalRegistration, AnimalVM>(); }); IMapper iMapper = config.CreateMapper(); model = iMapper.Map <AnimalRegistration, AnimalVM>(feed); } } model.speciess = new SelectList(_repo.Species.GetModel(), "id", "speciesName"); model.breeds = new SelectList(_repo.Breed.GetModel(), "id", "breedNameShort"); model.owners = new SelectList(_repo.OwnerKeeper.GetModel(), "id", "fullName"); model.farms = new SelectList(_repo.Farm.GetModel(), "id", "orgtanizationName"); model.keepers = new SelectList(_repo.keepers.GetModel(), "id", "fullName"); model.dams = new SelectList(_repo.AnimalRegistration.GetModel().Where(m => m.gender == "Male"), "id", "earTagNo"); model.sires = new SelectList(_repo.AnimalRegistration.GetModel().Where(m => m.gender == "Female"), "id", "earTagNo"); model.id = 0; model.declaredDate = DateTime.Now.Date; return(View(model)); }
public IActionResult DeleteAnimal(int id) { AnimalRegistration feed = _repo.AnimalRegistration.GetById(id); _repo.AnimalRegistration.Delete(id); return(Ok(feed)); }
public IActionResult DeleteAnimal(int id) { AnimalRegistration feed = _repo.AnimalRegistration.GetById(id); _repo.AnimalRegistration.Delete(id); return(RedirectToAction("Index")); }
public IActionResult Details(int id) { AnimalRegistration feed = _repo.AnimalRegistration.GetById(id); if (feed != null) { ViewBag.Image = Path.Combine(_host.WebRootPath, "\\images\\animal\\" + feed.earTagNo + ".jpg"); ViewBag.defaultimg = Path.Combine(_host.WebRootPath, "\\images\\cow.png"); } return(View(feed)); }
public IActionResult CheckEarTagUsed(string earTag) { AnimalRegistration ear = _repo.AnimalRegistration.GetByEartag(earTag); if (ear != null) { return(Json("NOTNULL")); } else { return(Json("NULL")); } }
public IActionResult Details(int id) { AnimalRegistration feed = _repo.AnimalRegistration.GetById(id); var animalDto = _mapper.Map <AnimalRegistrationDto>(feed); if (feed != null) { animalDto.DefaultImageUrl = Path.Combine(_host.WebRootPath, "\\images\\cow.png"); animalDto.ImageUrl = Path.Combine(_host.WebRootPath, "\\images\\animal\\" + feed.earTagNo + ".jpg"); } return(Ok(animalDto)); }
public ActionResult AddEditAnimal(int?id, [FromForm] AnimalVM model, IFormFile file) { try { if (ModelState.IsValid) { bool isNew = !id.HasValue; if (isNew) { //var config = new MapperConfiguration(cfg => //{ // cfg.CreateMap<AnimalVM, AnimalRegistration>(); //}); //IMapper iMapper = config.CreateMapper(); AnimalRegistration animal = _mapper.Map <AnimalRegistration>(model); animal.createdAt = DateTime.Now.ToShortDateString(); animal.EarTag = _repo.EarTag.GetByTag(model.earTagNo); animal.earTagId = animal.EarTag.id; _repo.AnimalRegistration.Insert(animal); _repo.Save(); var path = _host.WebRootPath + "\\images\\animal\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (file != null) { var fileName = Path.Combine(path, animal.earTagNo + ".jpg"); file.CopyTo(new FileStream(fileName, FileMode.Create)); } } else { AnimalRegistration animal = _mapper.Map <AnimalRegistration>(model); animal.EarTag = _repo.EarTag.GetByTag(model.earTagNo); animal.earTagId = animal.EarTag.id; animal.updatedBy = "admin"; _repo.AnimalRegistration.Update(animal); } } else { //model.speciess = new SelectList(_repo.Species.GetModel(), "id", "speciesName", model.speciesId); //model.breeds = new SelectList(_repo.Breed.GetModel(), "id", "breedNameShort", model.breedId); //model.owners = new SelectList(_repo.OwnerKeeper.GetModel(), "id", "fullName", model.ownerId); //model.keepers = new SelectList(_repo.keepers.GetModel(), "id", "fullName", model.keeperId); //model.farms = new SelectList(_repo.Farm.GetModel(), "id", "orgtanizationName", model.farmId); //model.dams = new SelectList(_repo.AnimalRegistration.GetModel().Where(m => m.gender == "Male"), "id", "earTagNo", model.damId); //model.sires = new SelectList(_repo.AnimalRegistration.GetModel().Where(m => m.gender == "Female"), "id", "earTagNo", model.sireId); model.declaredDate = DateTime.Now.Date; return(BadRequest(model)); } } catch (Exception ex) { throw ex; } // AnimalRegistration animal = _repo.AnimalRegistration. return(Ok(model)); }