public async Task <IActionResult> Edit(Guid id, ShoppingBasketViewModel vm) { var listROperation = await _pbo.ListNotDeletedAsync(); if (!listROperation.Success) { return(OperationErrorBackToIndex(listROperation.Exception)); } var pList = new List <SelectListItem>(); foreach (var item in listROperation.Result) { var listItem = new SelectListItem() { Value = item.Id.ToString(), Text = item.VatNumber.ToString() }; if (item.Id == vm.ProfileId) { listItem.Selected = true; } pList.Add(listItem); } ViewBag.Regions = pList; Draw("Edit", "fa-edit"); 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 void TestUpdateShoppingBasketAsync() { ContextSeeder.Seed(); var bo = new ShoppingBasketBusinessObject(); var resList = bo.ListAsync().Result; var item = resList.Result.FirstOrDefault(); var pbo = new ProfileBusinessObject(); var pro = pbo.List().Result.FirstOrDefault(); item.ProfileId = pro.Id; var resUpdate = bo.UpdateAsync(item).Result; resList = bo.ListNotDeletedAsync().Result; Assert.IsTrue(resList.Success && resUpdate.Success && resList.Result.First().ProfileId == pro.Id); }
public void TestUpdateShoppingBasketAsync() { ContextSeeder.Seed(); var bo = new ShoppingBasketBusinessObject(); var ebo = new EstablishmentBusinessObject(); var rbo = new RegionBusinessObject(); var cbo = new CompanyBusinessObject(); var reg = rbo.ListAsync().Result.Result.FirstOrDefault(); var com = cbo.ListAsync().Result.Result.FirstOrDefault(); var est = new Establishment("rua das papoilas", "09h00", "20h00", "sundays and holidays", reg.Id, com.Id); ebo.Create(est); var resList = bo.ListAsync(); var item = resList.Result.Result.FirstOrDefault(); item.EstablishmentId = est.Id; var resUpdate = bo.UpdateAsync(item).Result; var resNotList = bo.ListNotDeletedAsync().Result.Result; Assert.IsTrue(resUpdate.Success && resNotList.First().EstablishmentId == est.Id); }