public async Task <IActionResult> Edit(Guid id, [Bind("Id, InterestPointId, NewsLetterId")] InterestPointNewsletterViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var getOperation = await _bo.ReadAsync((Guid)id);

                if (!getOperation.Success)
                {
                    return(OperationErrorBackToIndex(getOperation.Exception));
                }
                if (getOperation.Result == null)
                {
                    return(NotFound());
                }
                var result = getOperation.Result;
                result.InterestPointId = vm.InterestPointId;
                result.NewsLetterId    = vm.NewsLetterId;
                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 TestUpdateInterestPointNewsletterAsync()
        {
            BoraNowSeeder.Seed();
            var ipnbo   = new InterestPointNewsletterBusinessObject();
            var resList = ipnbo.List();
            var item    = resList.Result.FirstOrDefault();

            var nbo  = new NewsletterBusinessObject();
            var cbo  = new CompanyBusinessObject();
            var ipbo = new InterestPointBusinessObject();
            var pbo  = new ProfileBusinessObject();

            var profile = new Profile("II", "AA");

            pbo.Create(profile);

            var news          = new Newsletter("New in town, this doughnut place is nuts", "New in town");
            var company       = new Company("a", "b", "c", "123333", profile.Id);
            var interestPoint = new InterestPoint("a", "b", "c", "d", "e", "f", "g", true, true, company.Id);

            nbo.Create(news);
            cbo.Create(company);
            ipbo.Create(interestPoint);

            var newInterestPointNews = new InterestPointNewsletter(interestPoint.Id, news.Id);

            item.InterestPointId = newInterestPointNews.InterestPointId;
            item.NewsLetterId    = newInterestPointNews.NewsLetterId;

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

            resList = ipnbo.ListAsync().Result;

            Assert.IsTrue(resUpdate.Success && resList.Success &&
                          resList.Result.First().InterestPointId == newInterestPointNews.InterestPointId && resList.Result.First().NewsLetterId == newInterestPointNews.NewsLetterId);
        }