public IHttpActionResult Update(UpdateRestaurant model, string id) { IHttpActionResult httpActionResult; ErrorsModel errors = new ErrorsModel(); Restaurants gv = this._db.Restaurants.FirstOrDefault(x => x.id == id); if (gv == null) { errors.Add("Nhà hàng này không tồn tại hoặc rỗng"); httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.NotFound, errors); } else { gv.name = model.name ?? model.name; gv.address = model.address ?? model.address; gv.type = model.type ?? model.type; this._db.Entry(gv).State = System.Data.Entity.EntityState.Modified; this._db.SaveChanges(); httpActionResult = Ok(new RestaurantModel(gv)); } return(httpActionResult); }
public RestaurantControllerTest() { //mock setup RestaurantMock = new Mock <IRestaurant>(); RestaurantsMock = new List <IRestaurant> { RestaurantMock.Object }; addRestaurantMock = new Mock <IAddRestaurant>(); updateRestaurantMock = new Mock <IUpdateRestaurant>(); Restaurant = new Restaurant(); Restaurants = new List <Restaurant>(); //viewmodels mock setup //sample models updateRestaurant = new UpdateRestaurant { }; //controller setup var RestaurantResultsMock = new Mock <IActionResult>(); mockRepo = new Mock <IRepositoryWrapper>(); var allRestaurants = GetRestaurants(); restaurantController = new RestaurantController(mockRepo.Object); }
// GET: Restaurant/Create public ActionResult Create() { string url = "ownerdata/getowners"; HttpResponseMessage httpResponse = client.GetAsync(url).Result; if (httpResponse.IsSuccessStatusCode) { UpdateRestaurant ViewModel = new UpdateRestaurant(); ViewModel.OwnersList = httpResponse.Content.ReadAsAsync <IEnumerable <OwnerDto> >().Result; url = "restaurantcategorydata/getrestaurantcategories"; httpResponse = client.GetAsync(url).Result; ViewModel.RestaurantCategoryList = httpResponse.Content.ReadAsAsync <IEnumerable <RestaurantCategoryDto> >().Result; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public ActionResult Edit(int id) { // Send a request to findrestaurant method to pull info string url = "restaurantdata/findrestaurant/" + id; HttpResponseMessage httpResponse = client.GetAsync(url).Result; if (httpResponse.IsSuccessStatusCode) { UpdateRestaurant ViewModel = new UpdateRestaurant(); ViewModel.Restaurant = httpResponse.Content.ReadAsAsync <RestaurantDto>().Result; url = "restaurantcategorydata/getrestaurantcategories"; httpResponse = client.GetAsync(url).Result; ViewModel.RestaurantCategoryList = httpResponse.Content.ReadAsAsync <IEnumerable <RestaurantCategoryDto> >().Result; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public void Update(UpdateRestaurant input) { Restaurant output = Mapper.Map <UpdateRestaurant, Restaurant>(input); _restaurantManager.Update(output); }