Exemplo n.º 1
0
        public async Task <IActionResult> Edit(UpdateAuthorCommand command)
        {
            try
            {
                var author     = _author.GetAuthor(command.AuthorId);
                var authResult = await _authService.AuthorizeAsync(User, author, "CanManageAuthor");

                //  var authResult1 = await _authService.AuthorizeAsync(User, person, "CanEditPerson");
                var authResult2 = await _authService.AuthorizeAsync(User, author, "ContentEditor");


                if (!authResult.Succeeded || !authResult2.Succeeded)
                {
                    return(new ForbidResult());
                }

                if (ModelState.IsValid)
                {
                    _author.UpdateAuthor(command);
                    return(RedirectToAction(nameof(View), new { id = command.AuthorId }));
                }
            }
            catch (Exception)
            {
                // Add a model-level error by using an empty string key
                ModelState.AddModelError(
                    string.Empty,
                    "An error occured updating author"
                    );
                _log.LogError("An error occured updating author");
            }

            //If we got to here, something went wrong
            return(View(command));
        }
        public IHttpActionResult UpdateAuthor(AuthorEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            AuthorServices service = CreateAuthorService();

            if (!service.UpdateAuthor(model))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Exemplo n.º 3
0
        public void IsChangingFirstNameCorrectly()
        {
            Author        author        = db.Authors.FirstOrDefault();
            EditAuthorDTO editAuthorDTO = new EditAuthorDTO
            {
                Id         = author.Id,
                FirstName  = "FirsteName1",
                MiddleName = author.MiddleName,
                LastName   = author.LastName,
                Birthday   = author.Birthday,
                Nickname   = author.Nickname,
                Country    = db.Countries.FirstOrDefault().Name
            };

            authorServices.UpdateAuthor(editAuthorDTO);

            Assert.AreEqual("FirsteName1", author.FirstName);
        }