public ActionResult AddEditAnimal(int?id, AiCreateVM model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    bool isNew = !id.HasValue;
                    if (isNew)
                    {
                        //model.UpdatedAt = DateTime.Now;
                        Ai animal = _mapper.Map <AiCreateVM, Ai>(model);
                        animal.earTagNo   = _repo.AnimalRegistration.GetById(model.AnimalId).earTagNo;
                        animal.BullEarTag = _repo.AnimalRegistration.GetById(model.BullId).earTagNo;
                        model.Animals     = new SelectList(_repo.AnimalRegistration.GetModel().Where(m => m.gender.ToUpper() == "FEMALE"), "id", "earTagNo");
                        model.Bulls       = new SelectList(_repo.AnimalRegistration.GetModel().Where(m => m.gender.ToUpper() == "MALE"), "id", "earTagNo");

                        _repo.Ais.Insert(animal);
                        _repo.Save();
                    }
                    else
                    {
                        Ai animal = _mapper.Map <AiCreateVM, Ai>(model);

                        animal.earTagNo   = _repo.AnimalRegistration.GetById(model.AnimalId).earTagNo;
                        animal.BullEarTag = _repo.AnimalRegistration.GetById(model.BullId).earTagNo;
                        _repo.Ais.Update(animal);
                    }
                }
                else
                {
                    model.Animals = new SelectList(_repo.AnimalRegistration.GetModel().Where(m => m.gender.ToUpper() == "FEMALE"), "id", "earTagNo");
                    model.Bulls   = new SelectList(_repo.AnimalRegistration.GetModel().Where(m => m.gender.ToUpper() == "MALE"), "id", "earTagNo");
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(RedirectToAction("Index"));
        }
        public IActionResult AddEditAnimal(int?id)
        {
            AiCreateVM model = new AiCreateVM();

            if (id.HasValue)
            {
                Ai feed = _repo.Ais.GetById(id.Value);


                if (feed != null)
                {
                    model = _mapper.Map <Ai, AiCreateVM>(feed);
                }
            }
            model.id = 0;
            model.previousInseminationDate = DateTime.Now;
            model.InseminationDate         = DateTime.Now;
            model.Animals = new SelectList(_repo.AnimalRegistration.GetModel(), "id", "earTagNo");
            model.Bulls   = new SelectList(_repo.AnimalRegistration.GetModel().Where(m => m.gender.ToUpper() == "MALE"), "id", "earTagNo");
            return(View(model));
        }