public IActionResult Edit(RestaurantEditViewModel rsVM) { string xmlFilePath = Path.GetFullPath("Data/resturant_reviews.xml"); try { restaurantReviews restaurantReviews = null; using (FileStream xs = new FileStream(xmlFilePath, FileMode.Open)) { XmlSerializer serializor = new XmlSerializer(typeof(restaurantReviews)); restaurantReviews = (restaurantReviews)serializor.Deserialize(xs); } restaurantReviewsRestaurant restaurant = restaurantReviews.restaurant[rsVM.Id]; restaurant.name = rsVM.Name; restaurant.address.street = rsVM.StreetAddress; restaurant.address.city = rsVM.City; restaurant.address.state_province = rsVM.ProvinceState; restaurant.address.postalCode = rsVM.PostalZipCode; restaurant.reviews.rivew.summary = rsVM.Summary; restaurant.reviews.rivew.rating.Value = (byte)rsVM.Rating; using (FileStream xs = new FileStream(xmlFilePath, FileMode.Create)) { XmlSerializer serializor = new XmlSerializer(typeof(restaurantReviews)); serializor.Serialize(xs, restaurantReviews); } } catch { return(RedirectToAction("Error")); } return(RedirectToAction("Index")); }
public IActionResult Edit(int?id) { if (id == null) { return(RedirectToAction("Error")); } string xmlFilePath = Path.GetFullPath("Data/resturant_reviews.xml"); restaurantReviews restaurantReviews = null; using (FileStream xs = new FileStream(xmlFilePath, FileMode.Open)) { XmlSerializer serializor = new XmlSerializer(typeof(restaurantReviews)); restaurantReviews = (restaurantReviews)serializor.Deserialize(xs); } if (id.Value < 0 || id.Value >= restaurantReviews.restaurant.Length) { return(RedirectToAction("Error")); } restaurantReviewsRestaurant restaurant = restaurantReviews.restaurant[id.Value]; RestaurantEditViewModel rest = RestaurantEditViewModel.GetRestaurantEditViewModel(restaurant); return(View(rest)); }
public static RestaurantEditViewModel GetRestaurantEditViewModel(restaurantReviewsRestaurant rs) { RestaurantEditViewModel rsVM = new RestaurantEditViewModel(); rsVM.Name = rs.name; rsVM.StreetAddress = rs.address.street; rsVM.City = rs.address.city; rsVM.ProvinceState = rs.address.state_province; rsVM.PostalZipCode = rs.address.postalCode; rsVM.Summary = rs.reviews.rivew.summary; rsVM.Rating = rs.reviews.rivew.rating.Value; return(rsVM); }