public void TestUpdateSameVATNumberCompanyAsync()
        {
            ContextSeeder.Seed();
            var bo  = new CompanyBusinessObject();
            var reg = new Company("Sonae", 12345);

            bo.Create(reg);
            reg.VatNumber = 123456789;
            var resUpdate = bo.UpdateAsync(reg).Result;

            Assert.IsTrue(resUpdate.Success && resUpdate.Message == "Vat number already exists");
        }
        public void TestUpdateSameNameCompanyAsync()
        {
            ContextSeeder.Seed();
            var bo  = new CompanyBusinessObject();
            var reg = new Company("Sonae", 12345);

            bo.Create(reg);
            reg.Name = "pingo ácido";
            var resUpdate = bo.UpdateAsync(reg).Result;

            Assert.IsTrue(resUpdate.Success && resUpdate.Message == "Name already exists");
        }
示例#3
0
        public void TestUpdateCompanyAsync()
        {
            ContextSeeder.Seed();
            var bo      = new CompanyBusinessObject();
            var resList = bo.ListAsync().Result;
            var item    = resList.Result.FirstOrDefault();

            item.Name = "Jerónimo Martins";
            var resUpdate = bo.UpdateAsync(item).Result;

            resList = bo.ListNotDeletedAsync().Result;
            Assert.IsTrue(resList.Success && resUpdate.Success && resList.Result.First().Name == "Jerónimo Martins");
        }
        public async Task <IActionResult> Edit(Guid id, [Bind("Id,Name, Representative, PhoneNumber, VatNumber, ProfileId")] CompanyViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync((Guid)id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(RecordNotFound());
                }
                var result = getOperation.Result;
                if (!vm.CompareToModel(result))
                {
                    result.Name           = vm.Name;
                    result.Representative = vm.Representative;
                    result.PhoneNumber    = vm.PhoneNumber;
                    result.VatNumber      = vm.VatNumber;
                    result.ProfileId      = vm.ProfileId;
                    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> Edit(Guid id, CompanyViewModel 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 = CompanyViewModel.Parse(getOperation.Result);
                        Draw("Edit", "fa-plus");
                        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 = CompanyViewModel.Parse(getOperation.Result);
                        Draw("Edit", "fa-plus");
                        return(View(vm));
                    }
                    else
                    {
                        return(OperationSuccess("The record was successfuly updated"));
                    }
                }
            }
            return(RedirectToAction(nameof(Index)));
        }