protected void OnRowUpdating(object sender, GridViewUpdateEventArgs e) { RestaurantDetailModel restaurant = new RestaurantDetailModel(); GridViewRow row = dgvrestaurantdetail.Rows[e.RowIndex]; restaurant.ID = int.Parse((row.Cells[1].Controls[0] as TextBox).Text); //dish.ID = Convert.ToInt32(dgvDishDetail.DataKeys[e.RowIndex].Values[0]); restaurant.RestaurantName = (row.Cells[2].Controls[0] as TextBox).Text; restaurant.Address = (row.Cells[3].Controls[0] as TextBox).Text; restaurant.ContactNo = (row.Cells[4].Controls[0] as TextBox).Text; restaurant.Website = (row.Cells[5].Controls[0] as TextBox).Text; using (OracleConnection con = new OracleConnection(connectionString)) { using (OracleCommand cmd = new OracleCommand("update restaurant set Restaurant_Name = '" + restaurant.RestaurantName + "',Address = '" + restaurant.Address + "',Contact_No='" + restaurant.ContactNo + "',Website='" + restaurant.Website + "' where Restaurant_ID = " + restaurant.ID)) { cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } dgvrestaurantdetail.EditIndex = -1; this.bindGrid(); }
private void bindGrid() { List <RestaurantDetailModel> restaurantslst = new List <RestaurantDetailModel>(); OracleConnection conn = new OracleConnection(connectionString); string query = "Select * from restaurant"; OracleCommand cmd = new OracleCommand(query, conn); conn.Open(); OracleDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { RestaurantDetailModel restaurant = new RestaurantDetailModel(); restaurant.ID = int.Parse(reader["Restaurant_ID"].ToString()); restaurant.RestaurantName = reader["Restaurant_Name"].ToString(); restaurant.Address = reader["Address"].ToString(); restaurant.ContactNo = reader["Contact_No"].ToString(); restaurant.Website = reader["Website"].ToString(); restaurantslst.Add(restaurant); } conn.Close(); dgvrestaurantdetail.DataSource = null; dgvrestaurantdetail.DataSource = restaurantslst; dgvrestaurantdetail.DataBind(); }
protected void btnAdd_Click(object sender, EventArgs e) { RestaurantDetailModel restaurant = new RestaurantDetailModel(); restaurant.RestaurantName = txtrestaurantname.Text.ToString(); restaurant.Address = txtaddress.Text.ToString(); restaurant.ContactNo = txtcontactno.Text.ToString(); restaurant.Website = txtwebsite.Text.ToString(); using (OracleConnection con = new OracleConnection(connectionString)) { using (OracleCommand cmd = new OracleCommand("Insert into restaurant(Restaurant_Name, Address, Contact_No, Website)Values('" + restaurant.RestaurantName + "','" + restaurant.Address + "','" + restaurant.ContactNo + "','" + restaurant.Website + "')")) { cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); txtrestaurantname.Text = ""; txtaddress.Text = ""; txtcontactno.Text = ""; txtwebsite.Text = ""; } this.bindGrid(); } }
public ActionResult Details(int id) { List <SelectListItem> dinergroup = new List <SelectListItem>(); List <SelectListItem> aantalpersonen = new List <SelectListItem>(); List <Diner> dinersevenements = new List <Diner>(); RestaurantDetailModel restaurantDetailModel = new RestaurantDetailModel(); restaurantDetailModel.restaurant = dinerrp.GetRestaurant(id); dinersevenements = dinerrp.GetAvailableDates(id); restaurantDetailModel.diner = dinerrp.GetDinerEvent(id); foreach (Diner diner in dinersevenements) { dinergroup.Add( new SelectListItem { Value = diner.ID.ToString(), Text = "Date: " + diner.StartDate.ToString("dd/MM") + " Time" + diner.StartDate.ToString("HH:mm") + "-" + diner.EndDate.ToString("HH:mm"), }); } for (int a = 1; a < 10; a++) { aantalpersonen.Add( new SelectListItem { Value = a.ToString(), Text = a.ToString(), }); } restaurantDetailModel.DinerEvents = dinergroup; restaurantDetailModel.NumberPersons = aantalpersonen; restaurantDetailModel.CrossTalkEvents = dinerrp.GetRandomTalksEvent(2); restaurantDetailModel.HearCrossEvents = dinerrp.GetRandomJazzEvent(2); return(View(restaurantDetailModel)); }
public GetRestaurantByIdResponse GetRestaurantById([FromBody] GetRestaurantByIdRequest request) { try { var restaurant = context.Restaurants.FirstOrDefault(f => f.RestaurantId == request.RestaurantId); var listItem = context.Items.Where(w => w.RestaurantId == request.RestaurantId).ToList() ?? new List <Item>(); var listItemCategory = context.ItemCategories.ToList(); var restaurantDetail = new RestaurantDetailModel(); var listImageString = restaurant.ImagePath.Split('\\'); string base64 = null; try { var imagePath = restaurant.ImagePath.Replace('/', '\\'); string contentRootPath = _webHostEnvironment.ContentRootPath; var path = Path.Combine(contentRootPath, imagePath); byte[] b = System.IO.File.ReadAllBytes(path); base64 = Convert.ToBase64String(b); } catch (Exception ex) { } restaurantDetail.RestaurantId = restaurant.RestaurantId; restaurantDetail.RestaurantName = restaurant.RestaurantName; restaurantDetail.RestaurantAddress = restaurant.RestaurantAddress; restaurantDetail.RestaurantEmail = restaurant.RestaurantEmail; restaurantDetail.RestaurantPhone = restaurant.RestaurantPhone; restaurantDetail.Longitude = restaurant.Longitude; restaurantDetail.Latitude = restaurant.Latitude; restaurantDetail.ImagePath = restaurant.ImagePath; restaurantDetail.ImageName = listImageString.LastOrDefault() ?? ""; restaurantDetail.ImageSrc = restaurant.ImageType + "," + base64; listItem?.ForEach(item => { var listItemCategoryByItem = listItemCategory.Where(w => w.CategoryId == item.ItemCategoryId).ToList(); var listImageString = item.MainImagePath.Split('\\'); string base64 = null; try { var imagePath = item.MainImagePath.Replace('/', '\\'); string contentRootPath = _webHostEnvironment.ContentRootPath; var path = Path.Combine(contentRootPath, imagePath); byte[] b = System.IO.File.ReadAllBytes(path); base64 = Convert.ToBase64String(b); } catch (Exception ex) { } restaurantDetail.ListItem.Add(new Models.items.ItemModel { ItemId = item.ItemId, ItemName = item.ItemName, RestaurantId = item.RestaurantId, ItemDescription = item.ItemDescription, ItemPrice = item.ItemPrice, ItemCategoryId = item.ItemCategoryId, MainImagePath = item.MainImagePath, ImageType = item.ImageType, ImageName = listImageString.LastOrDefault() ?? "", ImageSrc = item.ImageType + "," + base64, RestaurantLabel = restaurant?.RestaurantName ?? "", ItemCategoryLabel = String.Join(", ", listItemCategoryByItem.Select(w => w.CategoryName).ToList()) }); }); return(new GetRestaurantByIdResponse { RestaurantDetail = restaurantDetail, StatusCode = (int)HttpStatusCode.OK }); } catch (Exception e) { return(new GetRestaurantByIdResponse { StatusCode = (int)HttpStatusCode.BadRequest }); } }