public HttpResponseMessage GetAllCategory() { try { Mandi_CropMaster Mandi_CropMaster = new Mandi_CropMaster(); List <MandiCrop> objListMandiCrop = new List <MandiCrop>(); var getCategory = (from category in dbContext.Category select category).ToList(); if (getCategory != null) { foreach (var i in getCategory) { MandiCrop objMandi_Crop = new MandiCrop() { CategoryName = i.CategoryName, CategoryId = i.CategoryId }; objListMandiCrop.Add(objMandi_Crop); } Mandi_CropMaster.MandiCrops = objListMandiCrop; return(Request.CreateResponse(HttpStatusCode.OK, Mandi_CropMaster)); } else { objResponse.Message = "Failed to get categories"; return(Request.CreateResponse(HttpStatusCode.OK, objResponse)); } ; } catch (Exception ex) { Log.Info(Convert.ToString(ex.InnerException)); Log.Info(ex.Message); objCommonClasses.InsertExceptionDetails(ex, "MandiMasterController", "GetCategory"); return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, ex.Message)); } }
public HttpResponseMessage GetCrop(int CategoryId = 0) { try { if (CategoryId == 0) { Mandi_CropMaster Mandi_CropMaster = new Mandi_CropMaster(); List <MandiCrop> objListMandiCrop = new List <MandiCrop>(); //For getting list of crop from the table. var getCrop = (from crop in dbContext.Crop_Master select crop).ToList(); if (getCrop != null) { foreach (var i in getCrop) { MandiCrop objMandi_Crop = new MandiCrop() { CropId = i.CropId, CropName = i.CropName }; objListMandiCrop.Add(objMandi_Crop); } Mandi_CropMaster.MandiCrops = objListMandiCrop; return(Request.CreateResponse(HttpStatusCode.OK, Mandi_CropMaster)); } else { objResponse.Message = "Failed"; return(Request.CreateResponse(HttpStatusCode.OK, objResponse)); } } else { Mandi_CropMaster Mandi_CropMaster = new Mandi_CropMaster(); List <MandiCrop> objListMandiCrop = new List <MandiCrop>(); var categoryIdString = CategoryId.ToString(); //For getting list of crop from the table. var getCropbyCategoryId = (from crop in dbContext.Crop_Master where crop.CategoryId == categoryIdString select crop).ToList(); if (getCropbyCategoryId != null) { foreach (var i in getCropbyCategoryId) { MandiCrop objMandi_Crop = new MandiCrop() { CropId = i.CropId, CropName = i.CropName }; objListMandiCrop.Add(objMandi_Crop); } Mandi_CropMaster.MandiCrops = objListMandiCrop; return(Request.CreateResponse(HttpStatusCode.OK, Mandi_CropMaster)); } else { objResponse.Message = "Failed to get crop in reference of category "; return(Request.CreateResponse(HttpStatusCode.OK, objResponse)); } } } catch (Exception ex) { Log.Info(Convert.ToString(ex.InnerException)); Log.Info(ex.Message); objCommonClasses.InsertExceptionDetails(ex, "MandiMasterController", "GetCrop"); return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, ex.Message)); } }