public void TestCreateAndListRestaurantAsync() { RestaurantSeeder.Seed(); var dbo = new RestaurantBusinessObject(); var dr = new Restaurant("asdasd", "owewq", "123", "1232", "23ed", 4); var resCreate = dbo.CreateAsync(dr).Result; var resGet = dbo.ReadAsync(dr.Id).Result; Assert.IsTrue(resCreate.Success && resGet.Success && resGet.Result != null); }
public void TestCreateAndReadRestaurantAsync() { RestaurantSeeder.SeedCountries(); var bo = new RestaurantBusinessObject(); var rt = new Restaurant("Jade", "Avenida da Liberdade antes da rotunda", "13h00", "23h00", "monday", 24); var resCreate = bo.CreateAsync(rt).Result; var resGet = bo.ReadAsync(rt.Id).Result; Assert.IsTrue(resCreate.Success && resGet.Success && resGet.Result != null); }
public async Task <IActionResult> CreateAsync([FromBody] RestaurantViewModel vm) { var newItem = vm.ToModel(); var result = await _bo.CreateAsync(newItem); if (!result.Success) { return(InternalServerError(result.Exception)); } return(Created(Request.Path.Value, null)); }
public async Task <IActionResult> New(RestaurantViewModel vm) { if (ModelState.IsValid) { var model = vm.ToModel(); var createOperation = await _bo.CreateAsync(model); if (!createOperation.Success) { return(OperationErrorBackToIndex(createOperation.Exception)); } else { return(OperationSuccess("The record was successfuly created")); } } return(View(vm)); }
public async Task <IActionResult> Create([Bind("Name", "Address", "OpenningHours", "ClosingHours", "ClosingDays", "TableCount")] RestaurantViewModel vm) { if (ModelState.IsValid) { var Restaurant = vm.ToRestaurant(); var createOperation = await _bo.CreateAsync(Restaurant); if (!createOperation.Success) { return(View("Error", new ErrorViewModel() { RequestId = createOperation.Exception.Message })); } return(RedirectToAction(nameof(Index))); } return(View(vm)); }