示例#1
0
        public void TestUpdateSameNameRegionAsync()
        {
            ContextSeeder.Seed();
            var bo  = new RegionBusinessObject();
            var reg = new Region("another");

            bo.Create(reg);
            reg.Name = "Covilhã";
            var resUpdate = bo.UpdateAsync(reg).Result;

            Assert.IsTrue(resUpdate.Success);
        }
示例#2
0
        public void TestUpdateRegionnAsync()
        {
            ContextSeeder.Seed();
            var bo      = new RegionBusinessObject();
            var resList = bo.ListAsync().Result;
            var item    = resList.Result.FirstOrDefault();

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

            resList = bo.ListNotDeletedAsync().Result;
            Assert.IsTrue(resList.Success && resUpdate.Success && resList.Result.First().Name == "another");
        }
示例#3
0
        public async Task <IActionResult> Edit(Guid id, RegionViewModel 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);
                        getOperation      = await _bo.ReadAsync((Guid)id);

                        if (!getOperation.Success)
                        {
                            return(OperationErrorBackToIndex(getOperation.Exception));
                        }
                        if (getOperation.Result == null)
                        {
                            return(RecordNotFound());
                        }

                        vm = RegionViewModel.Parse(getOperation.Result);
                        ViewData["Title"] = "Edit Region";
                        var crumbs = GetCrumbs();
                        crumbs.Add(new BreadCrumb()
                        {
                            Action = "Edit", Controller = "Regions", Icon = "fa-search", Text = "Edit"
                        });
                        ViewData["BreadCrumbs"] = crumbs;
                        return(View(vm));
                    }
                    if (!updateOperation.Result)
                    {
                        TempData["Alert"] = AlertFactory.GenerateAlert(NotificationType.Danger, updateOperation.Message);
                        getOperation      = await _bo.ReadAsync((Guid)id);

                        if (!getOperation.Success)
                        {
                            return(OperationErrorBackToIndex(getOperation.Exception));
                        }
                        if (getOperation.Result == null)
                        {
                            return(RecordNotFound());
                        }

                        vm = RegionViewModel.Parse(getOperation.Result);
                        ViewData["Title"] = "Edit Region";
                        var crumbs = GetCrumbs();
                        crumbs.Add(new BreadCrumb()
                        {
                            Action = "Edit", Controller = "Regions", Icon = "fa-search", Text = "Edit"
                        });
                        ViewData["BreadCrumbs"] = crumbs;
                        return(View(vm));
                    }
                    else
                    {
                        return(OperationSuccess("The record was successfuly updated"));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }