Exemplo n.º 1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("Id, Title, Description")] NewsletterViewModel 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;
                result.Title       = vm.Title;
                result.Description = vm.Description;
                var updateOperation = await _bo.UpdateAsync(result);

                if (!updateOperation.Success)
                {
                    return(OperationErrorBackToIndex(updateOperation.Exception));
                }
                else
                {
                    return(OperationSuccess("The record was successfuly updated"));
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 2
0
        public void TestUpdateNewsletterAsync()
        {
            BoraNowSeeder.Seed();
            var nbo     = new NewsletterBusinessObject();
            var resList = nbo.List();
            var item    = resList.Result.FirstOrDefault();

            var newNews = new Newsletter("try it now, new burger down town", "Lisbon new burger place");

            item.Description = newNews.Description;
            item.Title       = newNews.Title;

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

            resList = nbo.ListAsync().Result;

            Assert.IsTrue(resUpdate.Success && resList.Success &&
                          resList.Result.First().Description == newNews.Description && resList.Result.First().Title == newNews.Title);
        }