// GET: Livestock/Create public ActionResult AddFarmLivestock(int?farmId) { var model = new FarmLivestockViewModel { LivestockBreedList = LivestockBreedService.Get().ToList(), FarmId = farmId.Value, AnimalGenderDropDown = GetMyAnimalGender(null) }; return(PartialView(model)); }
// GET: Livestock/Create public ActionResult AddFarmLivestock(int?farmId) { var model = new FarmLivestockViewModel { FarmId = farmId.Value, AnimalGenderDropDown = GetMyAnimalGender(null), /// LivestockTypeDropDown = GetLivestockType(null), //LivestockDropDown = GetLivestockEmpty(null) LivestockDropDown = GetLivestock(null) }; return(View(model)); }
// GET: Livestock public ActionResult Index(int?farmId) { string userId = User.Identity.GetUserId(); FarmLivestockViewModel model = new FarmLivestockViewModel { MyFarmLivestock = FarmLivestockService.Get().Where( x => x.Farm.ApplicationUserId == userId && x.IsActive ).ToList() }; return(View(model)); }
public ActionResult EditLivestock(int id) { FarmLivestockViewModel model = null; var config = new MapperConfiguration(cfg => { cfg.CreateMap <CropPrice, PriceViewModel>(); }); IMapper iMapper = config.CreateMapper(); FarmLivestock thisLivestock = FarmLivestockService.GetById(id); model = iMapper.Map <FarmLivestock, FarmLivestockViewModel>(thisLivestock); return(PartialView("_AddCropToFarmDialog", model)); }
public ActionResult AddLivestockToFarm(FarmLivestockViewModel model) { if (ModelState.IsValid) { if (model.Id > 0) { FarmLivestock updateDetail = FarmLivestockService.GetById(model.Id); updateDetail.Breed = model.Breed; updateDetail.LivestockId = model.LivestockId; updateDetail.Population = model.Population; updateDetail.QuantityAvailable = model.QuantityAvailable; updateDetail.Weight = model.Weight; updateDetail.GenderId = model.GenderId; updateDetail.HitMarketDate = model.HitMarketDate; updateDetail.Other = model.Other; FarmLivestockService.Update(updateDetail); return(RedirectToAction("Index", new { farmid = model.FarmId })); } var newFarmLivestock = new FarmLivestock { Breed = model.Breed, FarmId = model.FarmId, GenderId = model.GenderId, Population = model.Population, QuantityAvailable = model.QuantityAvailable, Weight = model.Weight, HitMarketDate = model.HitMarketDate, IsActive = true, DateCreated = DateTime.Now, Other = model.Other, LivestockId = model.LivestockId, IsAvailable = false }; FarmLivestockService.Create(newFarmLivestock); return(RedirectToAction("Index", new { farmid = model.FarmId })); } model.AnimalGenderDropDown = GetMyAnimalGender(model.GenderId); return(View(model)); }
public ActionResult UpdateDetail(int id) { FarmLivestockViewModel model = null; var config = new MapperConfiguration(cfg => { cfg.CreateMap <FarmLivestock, FarmLivestockViewModel>() .ReverseMap(); }); IMapper iMapper = config.CreateMapper(); FarmLivestock thisLivestock = FarmLivestockService.GetById(id); model = iMapper.Map <FarmLivestock, FarmLivestockViewModel>(thisLivestock); //model.LivestockTypeId = thisLivestock.Livestock.LivestockTypeId.Value; //model.LivestockTypeDropDown = GetLivestockType(model.LivestockTypeId); model.LivestockDropDown = GetLivestock(thisLivestock.LivestockId); model.AnimalGenderDropDown = GetAnimalGender(thisLivestock.GenderId); return(View("AddFarmLivestock", model)); }
public ActionResult AddLivestockToFarm(FarmLivestockViewModel model) { FarmLivestock checkFarmLivestock = LivestockAlreadyAdded(model.LivestockBreedId, model.FarmId); if (checkFarmLivestock != null) { model.AnimalGenderDropDown = GetMyAnimalGender(model.GenderId); return(RedirectToAction("AddFarmLivestock", new { farmId = model.FarmId, BreedId = model.LivestockBreedId })); } if (ModelState.IsValid) { var newFarmLivestock = new FarmLivestock { LivestockBreedId = model.LivestockBreedId, FarmId = model.FarmId, GenderId = model.GenderId, Population = model.Population, QuantityAvailable = model.QuantityAvailable, Weight = model.Weight, HitMarketDate = model.HitMarketDate, IsActive = true, DateCreated = DateTime.Now }; FarmLivestockService.Create(newFarmLivestock); return(RedirectToAction("AddFarmLivestock", new { farmId = model.FarmId, BreedId = model.LivestockBreedId })); } model.AnimalGenderDropDown = GetMyAnimalGender(model.GenderId); return(View(model)); //Local method to get a ducplicate livestock already added to // a particular farm FarmLivestock LivestockAlreadyAdded(int breedId, int farmId) => FarmLivestockService.Get().Where(x => x.LivestockBreedId == breedId && x.FarmId == farmId).FirstOrDefault(); }