private void button2_Click(object sender, EventArgs e) { RestaurantsBsn restaurantsBsn = new RestaurantsBsn(); RestaurantsModel restaurantsModel = new RestaurantsModel(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text); restaurantsBsn.Insert(restaurantsModel); }
public List <RestaurantsModel> ReadRestaurants() { try { OpenSqlConnection(); CreateCommandSc("SelectAllRestaurants"); SqlDataReader sqlDataReader = GetExecuteReader(); List <RestaurantsModel> restaurantsList = new List <RestaurantsModel>(); while (sqlDataReader.Read()) { RestaurantsModel restaurantsModel = new RestaurantsModel(); restaurantsModel.RestaurantId = Convert.ToInt32(sqlDataReader["RestaurantId"]); restaurantsModel.Name = sqlDataReader["Name"].ToString(); restaurantsModel.Address = sqlDataReader["Address"].ToString(); restaurantsModel.WebSite = sqlDataReader["WebSite"].ToString(); restaurantsModel.Description = sqlDataReader["Description"].ToString(); restaurantsList.Add(restaurantsModel); } return(restaurantsList); } catch (SqlException ex) { throw new System.Exception(ex.Message); } finally { CloseSqlConnection(); } }
public void InsertRestaurant(RestaurantsModel restaurantsModel) { using (var context = new WebShopContext()) { context.RestaurantsModel.Add(restaurantsModel); context.SaveChanges(); } }
public void InsertRestaurant(RestaurantsModel restaurantsModel) { string curFile = @"C:\temp\Restaurants.json"; if (File.Exists(curFile)) { List <RestaurantsModel> listRestaurants = ReadRestaurants(); listRestaurants.Add(restaurantsModel); var jsonString = JsonSerializer.Serialize(listRestaurants); File.WriteAllText("C:\\temp\\Restaurants.json", jsonString); } else { List <RestaurantsModel> listRestaurants = new List <RestaurantsModel>(); listRestaurants.Add(restaurantsModel); var jsonString = JsonSerializer.Serialize(listRestaurants); File.WriteAllText("C:\\temp\\Restaurants.json", jsonString); } }
public void UpdateRestaurant(RestaurantsModel restaurantsModel) { using (var context = new WebShopContext()) { var result = context.RestaurantsModel.SingleOrDefault(b => b.RestaurantId == restaurantsModel.RestaurantId); if (result != null) { try { context.RestaurantsModel.Attach(restaurantsModel); context.Entry(restaurantsModel).State = EntityState.Modified; context.SaveChanges(); } catch (Exception ex) { throw; } } } }
public void UpdateRestaurant(RestaurantsModel restaurantsModel) { try { OpenSqlConnection(); SqlCommand sqlCommand = CreateCommandSc("UpdateRestaurant"); sqlCommand.Parameters.Add(new SqlParameter("@RestaurantId", restaurantsModel.RestaurantId)); sqlCommand.Parameters.Add(new SqlParameter("@Name", restaurantsModel.Name)); sqlCommand.Parameters.Add(new SqlParameter("@Address", restaurantsModel.Address)); sqlCommand.Parameters.Add(new SqlParameter("@WebSite", restaurantsModel.WebSite)); sqlCommand.Parameters.Add(new SqlParameter("@Description", restaurantsModel.Description)); } catch (SqlException ex) { throw new System.Exception(ex.Message); } finally { CloseSqlConnection(); } }
public async Task <IActionResult> UpdateRestaurantAsync(int id, [FromBody] RestaurantsModel model) { if (!ModelState.IsValid) { return(StatusCode((int)HttpStatusCode.InternalServerError, GetErrorList(ModelState))); } RestaurantObjects result; try { People currentUser = this.GetCurrentUser(); result = await Services.UpdateRestaurantAsync( currentUser.ThePersonAsEmployer.Id, id, model.Name, model.Description); } catch (Exception ex) { return(StatusCode((int)HttpStatusCode.InternalServerError, GetErrorList(ex))); } return(Ok(result)); }
public async Task <IViewComponentResult> InvokeAsync(int entityId, bool isFilterApplied, string cuisines) { RestaurantsModel restaurantsModel = new RestaurantsModel(); restaurantsModel.Restaurants = new List <RestaurantDO>(); restaurantsModel.MapDetails = new List <MapDetailsDO>(); List <string> lstIntersect = new List <string>(); List <CuisinesDO> lstAllCuisines = new List <CuisinesDO>(); //restaurantsModel.Cuisines = new List<string>(); restaurantsModel.CuisineDetails = new List <CuisinesDO>(); ZomatoRestaurantDO zomatoRestaurantDO = new ZomatoRestaurantDO(); zomatoRestaurantDO = await GetRestaurants(entityId); restaurantsModel.LocLatLong = await GetLocationDetails(entityId); if (zomatoRestaurantDO != null && zomatoRestaurantDO.results_found > 0 && zomatoRestaurantDO.results_shown > 0 && zomatoRestaurantDO.restaurants != null && zomatoRestaurantDO.restaurants.Length > 0) { List <string> lstFilterCuisines = new List <string>(); if (string.IsNullOrEmpty(cuisines) == false) { lstFilterCuisines = cuisines.Split(',').ToList <string>(); } foreach (var res in zomatoRestaurantDO.restaurants) { if (string.IsNullOrEmpty(res.restaurant.cuisines) == false) { var tempRestCuisines = res.restaurant.cuisines.Split(','); List <string> lstResCuisines = new List <string>(); if (tempRestCuisines != null && tempRestCuisines.Count() > 0) { for (int i = 0; i < tempRestCuisines.Count(); i++) { lstResCuisines.Add(tempRestCuisines[i].Trim()); } } if (lstResCuisines != null && lstResCuisines.Count > 0) { //lstAllCuisines.AddRange(lstResCuisines); foreach (var cuisine in lstResCuisines) { if (lstAllCuisines.Where(m => m.Name.ToLower().Trim() == cuisine.ToLower().Trim()).Count() > 0) { lstAllCuisines.Where(m => m.Name.ToLower().Trim() == cuisine.ToLower().Trim()) .First().Count += 1; } else { lstAllCuisines.Add(new CuisinesDO() { Name = cuisine, Count = 1, IsChecked = false }); } } if (isFilterApplied) { lstFilterCuisines.ForEach(m => m.ToLower().TrimStart().TrimEnd()); lstResCuisines.ForEach(m => m.ToLower().TrimStart().TrimEnd()); lstIntersect = lstFilterCuisines.Intersect(lstResCuisines).ToList <string>(); } } } if ((isFilterApplied && lstIntersect != null && lstIntersect.Count > 0) || (isFilterApplied && lstFilterCuisines.Count == 0) || isFilterApplied == false) { restaurantsModel.Restaurants.Add(GetRestaurantDO(res.restaurant)); restaurantsModel.MapDetails.Add(GetMapDetails(res.restaurant)); } } if (restaurantsModel.MapDetails.Count > 0) { restaurantsModel.JsonMapDetails = JsonConvert.SerializeObject(restaurantsModel.MapDetails); } if (lstAllCuisines != null && lstAllCuisines.Count > 0) { lstAllCuisines.ForEach(m => m.Name.Trim()); restaurantsModel.CuisineDetails.AddRange(lstAllCuisines.Distinct().OrderBy(m => m.Name)); } if (isFilterApplied && lstAllCuisines != null && lstAllCuisines.Count > 0) { foreach (var item in restaurantsModel.CuisineDetails) { bool check = false; if (lstFilterCuisines.Where(m => m.ToLower().Trim() == item.Name.ToLower().Trim()).Count() > 0) { check = true; } item.IsChecked = check; } } } return(View(restaurantsModel)); }
public void Update(RestaurantsModel restaurantsModel) { restaurantsData.UpdateRestaurant(restaurantsModel); }
public void Insert(RestaurantsModel restaurantsModel) { restaurantsData.InsertRestaurant(restaurantsModel); }
public void UpdateRestaurant(RestaurantsModel restaurantsModel) { throw new NotImplementedException(); }