public ViewResult Products() { CropsViewModel cropsViewModel = new CropsViewModel(repository.Crops); return(View("Crops", cropsViewModel)); }
public ActionResult Crops() { SmartFarmingEntities db = new SmartFarmingEntities(); List <CropDetails> foodCrops = (from c in db.Crops where c.type_id == 1 select new CropDetails { id = c.id, CropName = c.CropName, CropImage = c.CropImage, Kharif = (bool)c.Kharif, Rabi = (bool)c.Rabi, Zaid = (bool)c.Zaid }).ToList(); foreach (var item in foodCrops) { List <string> season = new List <string>(); if (item.Kharif == true) { season.Add("Kharif"); } if (item.Rabi == true) { season.Add("Rabi"); } if (item.Zaid == true) { season.Add("Zaid"); } item.Season = string.Join(", ", season); } List <CropDetails> cashCrops = (from c in db.Crops where c.type_id == 2 select new CropDetails { id = c.id, CropName = c.CropName, CropImage = c.CropImage, Kharif = (bool)c.Kharif, Rabi = (bool)c.Rabi, Zaid = (bool)c.Zaid }).ToList(); foreach (var item in cashCrops) { List <string> season = new List <string>(); if (item.Kharif == true) { season.Add("Kharif"); } if (item.Rabi == true) { season.Add("Rabi"); } if (item.Zaid == true) { season.Add("Zaid"); } item.Season = string.Join(", ", season); } List <CropDetails> plantationCrops = (from c in db.Crops where c.type_id == 3 select new CropDetails { id = c.id, CropName = c.CropName, CropImage = c.CropImage, Kharif = (bool)c.Kharif, Rabi = (bool)c.Rabi, Zaid = (bool)c.Zaid }).ToList(); foreach (var item in plantationCrops) { List <string> season = new List <string>(); if (item.Kharif == true) { season.Add("Kharif"); } if (item.Rabi == true) { season.Add("Rabi"); } if (item.Zaid == true) { season.Add("Zaid"); } item.Season = string.Join(", ", season); } List <CropDetails> horticultureCrops = (from c in db.Crops where c.type_id == 4 select new CropDetails { id = c.id, CropName = c.CropName, CropImage = c.CropImage, Kharif = (bool)c.Kharif, Rabi = (bool)c.Rabi, Zaid = (bool)c.Zaid }).ToList(); foreach (var item in horticultureCrops) { List <string> season = new List <string>(); if (item.Kharif == true) { season.Add("Kharif"); } if (item.Rabi == true) { season.Add("Rabi"); } if (item.Zaid == true) { season.Add("Zaid"); } item.Season = string.Join(", ", season); } CropsViewModel model = new CropsViewModel(); model.FoodCrops = foodCrops; model.CashCrops = cashCrops; model.PlantationCrops = plantationCrops; model.HorticultureCrops = horticultureCrops; return(View(model)); }
public CropsPage() { InitializeComponent(); BindingContext = new CropsViewModel(); }