public async Task <IActionResult> PutAsync(int id, [FromBody] ExhibitPageArgs2 args) { // if font family is not specified, fallback to the configured default font family if (args != null && args.FontFamily == null) { args.FontFamily = _exhibitPagesConfig.Value.DefaultFontFamily; } ValidateExhibitPageArgs(args); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_entityIndex.Exists(ResourceType.ExhibitPage, id)) { return(NotFound()); } // ReSharper disable once PossibleNullReferenceException (args == null is handled through ModelState.IsValid) if (!UserPermissions.IsAllowedToEdit(User.Identity, args.Status, _entityIndex.Owner(ResourceType.ExhibitPage, id))) { return(Forbid()); } var oldStatus = _entityIndex.Status(ResourceType.ExhibitPage, id).GetValueOrDefault(); if (args.Status == ContentStatus.Unpublished && oldStatus != ContentStatus.Published) { return(BadRequest(ErrorMessages.CannotBeUnpublished(ResourceType.ExhibitPage))); } // ReSharper disable once PossibleInvalidOperationException (.Value is safe here since we know the entity exists) var currentPageType = _exhibitPageIndex.PageType(id).Value; // ReSharper disable once PossibleNullReferenceException (args == null is handled through ModelState.IsValid) if (currentPageType != args.Type) { return(StatusCode(422, ErrorMessages.CannotChangeExhibitPageType(currentPageType, args.Type))); } // validation passed, emit event var ev = new ExhibitPageUpdated3 { Id = id, UserId = User.Identity.GetUserIdentity(), Properties = args, Timestamp = DateTimeOffset.Now }; await _eventStore.AppendEventAsync(ev); return(StatusCode(204)); }
public async Task <IActionResult> UpdateByIdAsync(int id, [FromBody] TagArgs args) { ValidateTagArgs(args); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_entityIndex.Exists(ResourceType.Tag, id)) { return(NotFound()); } if (!UserPermissions.IsAllowedToEdit(User.Identity, args.Status, _entityIndex.Owner(ResourceType.Tag, id))) { return(Forbid()); } var oldStatus = _entityIndex.Status(ResourceType.Tag, id).GetValueOrDefault(); if (args.Status == ContentStatus.Unpublished && oldStatus != ContentStatus.Published) { return(BadRequest(ErrorMessages.CannotBeUnpublished(ResourceType.Tag))); } var tagIdWithSameTitle = _tagIndex.GetIdByTagTitle(args.Title); if (tagIdWithSameTitle != null && tagIdWithSameTitle != id) { return(StatusCode(409, ErrorMessages.TagNameAlreadyUsed)); } var ev = new TagUpdated { Id = id, UserId = User.Identity.GetUserIdentity(), Properties = args, Timestamp = DateTimeOffset.Now, }; await _eventStore.AppendEventAsync(ev); return(NoContent()); }
public async Task <IActionResult> PutAsync(int id, [FromBody] RouteArgs args) { ValidateRouteArgs(args); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_entityIndex.Exists(ResourceType.Route, id)) { return(NotFound()); } if (!UserPermissions.IsAllowedToEdit(User.Identity, args.Status, _entityIndex.Owner(ResourceType.Route, id))) { return(Forbid()); } var oldStatus = _entityIndex.Status(ResourceType.Route, id).GetValueOrDefault(); if (args.Status == ContentStatus.Unpublished && oldStatus != ContentStatus.Published) { return(BadRequest(ErrorMessages.CannotBeUnpublished(ResourceType.Route))); } // validation passed, emit event var ev = new RouteUpdated { Id = id, UserId = User.Identity.GetUserIdentity(), Properties = args, Timestamp = DateTimeOffset.Now, }; await _eventStore.AppendEventAsync(ev); return(StatusCode(204)); }