public void TestUpdateRestaurantAsync()
        {
            ContextSeeders.Seed();
            var mbo     = new RestaurantBusinessObject();
            var resList = mbo.List();
            var item    = resList.Result.FirstOrDefault();

            var newRestaurant = new Restaurant("Bartolomeu", "Rua tulipa, numero 234, Ericeira", "11:00", "22:00",
                                               "Segunfa-feira", 20);

            item.Name          = newRestaurant.Name;
            item.Address       = newRestaurant.Address;
            item.OpenningHours = newRestaurant.OpenningHours;
            item.ClosingHours  = newRestaurant.ClosingHours;
            item.ClosingDays   = newRestaurant.ClosingDays;
            item.TableCount    = newRestaurant.TableCount;


            var resUpdate = mbo.UpdateAsync(item).Result;

            resList = mbo.ListAsync().Result;

            Assert.IsTrue(resList.Success && resUpdate.Success &&
                          resList.Result.First().Name == newRestaurant.Name &&
                          resList.Result.First().Address == newRestaurant.Address &&
                          resList.Result.First().OpenningHours == newRestaurant.OpenningHours &&
                          resList.Result.First().ClosingHours == newRestaurant.ClosingHours &&
                          resList.Result.First().ClosingDays == newRestaurant.ClosingDays &&
                          resList.Result.First().TableCount == newRestaurant.TableCount);
        }
        public async Task <IActionResult> Edit(Guid id, RestaurantViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync(id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(RecordNotFound());
                }
                var result = getOperation.Result;
                if (!vm.CompareToModel(result))
                {
                    result = vm.ToModel(result);
                    var updateOperation = await _bo.UpdateAsync(result);

                    if (!updateOperation.Success)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Exception);
                        return(View(vm));
                    }
                    else
                    {
                        return(OperationSuccess("The record was successfuly updated"));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Update([FromBody] RestaurantViewModel vm)
        {
            var getResult = await _bo.ReadAsync(vm.Id);

            if (!getResult.Success)
            {
                return(InternalServerError(getResult.Exception));
            }
            var item = getResult.Result;

            if (item == null)
            {
                return(NotFound());
            }
            if (vm.CompareToModel(item))
            {
                return(NotModified());
            }
            item = vm.ToModel(item);
            var updateResult = await _bo.UpdateAsync(item);

            if (!updateResult.Success)
            {
                return(InternalServerError(updateResult.Exception));
            }
            return(Ok());
        }
Exemplo n.º 4
0
        public void TestUpdateRestaurantAsync()
        {
            RestaurantSeeder.Seed();
            var bo      = new RestaurantBusinessObject();
            var resList = bo.ListAsync().Result;
            var item    = resList.Result.FirstOrDefault();

            item.Name = "another";
            var resUpdate = bo.UpdateAsync(item).Result;

            resList = bo.ListNonDeletedAsync().Result;
            Assert.IsTrue(resList.Success && resUpdate.Success && resList.Result.First().Name == "another");
        }
Exemplo n.º 5
0
        public void TestUpdateRestaurantAsync()
        {
            RestaurantSeeder.SeedCountries();
            var bo      = new RestaurantBusinessObject();
            var resList = bo.ListAsync().Result;
            var item    = resList.Result.FirstOrDefault();

            item.OpeningHours = "9h00";
            var resUpdate = bo.UpdateAsync(item).Result;

            resList = bo.ListUnDeletedAsync().Result;
            Assert.IsTrue(resList.Success && resUpdate.Success && resList.Result.First().OpeningHours == "9h00");
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id, Name, Address, OpenningHours, ClosingHours, ClosingDays, TableCount")] RestaurantViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync((Guid)id);

                if (!getOperation.Success)
                {
                    return(View("Error", new ErrorViewModel()
                    {
                        RequestId = getOperation.Exception.Message
                    }));
                }
                if (getOperation.Result == null)
                {
                    return(NotFound());
                }
                var result = getOperation.Result;
                result.Name          = vm.Name;
                result.Address       = vm.Address;
                result.OpenningHours = vm.OpenningHours;
                result.ClosingHours  = vm.ClosingHours;
                result.ClosingDays   = vm.ClosingDays;
                result.TableCount    = vm.TableCount;
                var updateOperation = await _bo.UpdateAsync(result);

                if (!updateOperation.Success)
                {
                    return(View("Error", new ErrorViewModel()
                    {
                        RequestId = updateOperation.Exception.Message
                    }));
                }
            }
            return(RedirectToAction(nameof(Index)));
        }