コード例 #1
0
        public void TestUpdateNewsletter()
        {
            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.Update(item);

            resList = nbo.List();

            Assert.IsTrue(resUpdate.Success && resList.Success &&
                          resList.Result.First().Description == newNews.Description && resList.Result.First().Title == newNews.Title);
        }
コード例 #2
0
        public ActionResult Update([FromBody] NewsletterViewModel vm)
        {
            var currentResult = _bo.Read(vm.Id);

            if (!currentResult.Success)
            {
                return(new ObjectResult(HttpStatusCode.InternalServerError));
            }
            var current = currentResult.Result;

            if (current == null)
            {
                return(NotFound());
            }
            if (current.Description == vm.Description && current.Title == vm.Title)
            {
                return(new ObjectResult(HttpStatusCode.NotModified));
            }

            if (current.Description != vm.Description)
            {
                current.Description = vm.Description;
            }
            if (current.Title != vm.Title)
            {
                current.Title = vm.Title;
            }

            var updateResult = _bo.Update(current);

            if (!updateResult.Success)
            {
                return(new ObjectResult(HttpStatusCode.InternalServerError));
            }
            return(Ok());
        }