コード例 #1
0
        public async Task <IActionResult> Edit(Guid id, DishViewModel 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)));
        }
コード例 #2
0
        public void TestUpdateDishAsync()
        {
            ContextSeeders.Seed();
            var dbo     = new DishBusinessObject();
            var resList = dbo.List();
            var item    = resList.Result.FirstOrDefault();


            var drbo = new DietaryRestrictionBusinessObject();


            var dr      = new DietaryRestriction("vegan");
            var newDish = new Dish("ok", dr.Id);


            drbo.Create(dr);


            item.DietaryRestrictionId = newDish.DietaryRestrictionId;
            item.Name = newDish.Name;

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

            resList = dbo.ListAsync().Result;

            Assert.IsTrue(resList.Success && resUpdate.Success &&
                          resList.Result.First().DietaryRestrictionId == newDish.DietaryRestrictionId &&
                          resList.Result.First().Name == newDish.Name);
        }
コード例 #3
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id, Name, DietaryRestrictionId")] DishViewModel 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.DietaryRestrictionId = vm.DietaryRestrictionId;
                var updateOperation = await _bo.UpdateAsync(result);

                if (!updateOperation.Success)
                {
                    return(View("Error", new ErrorViewModel()
                    {
                        RequestId = updateOperation.Exception.Message
                    }));
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
コード例 #4
0
        public async Task <IActionResult> Update([FromBody] DishViewModel 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());
        }
コード例 #5
0
        public void TestUpdateDishAsync()
        {
            RestaurantSeeder.SeedCountries();
            var bo      = new DishBusinessObject();
            var resList = bo.ListAsync().Result;
            var item    = resList.Result.FirstOrDefault();

            item.Name = "Pizza";
            var resUpdate  = bo.UpdateAsync(item).Result;
            var resNotList = bo.ListUnDeletedAsync().Result;

            Assert.IsTrue(resUpdate.Success && resNotList.Result.First().Name == "Pizza");
        }