public async Task <IActionResult> UpdateTopic( [ModelBinder(typeof(JsonModelBinder <TopicDto>))] Delta <TopicDto> topicDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } var currentTopic = await _topicService.GetTopicByIdAsync(topicDelta.Dto.Id); if (currentTopic == null) { return(Error(HttpStatusCode.NotFound, "topic", "not found")); } topicDelta.Merge(currentTopic); await _topicService.UpdateTopicAsync(currentTopic); var topicsRootObject = new TopicsRootObject(); var topicDto = _dtoHelper.PrepareTopicDTO(currentTopic); topicsRootObject.Topics.Add(topicDto); var json = JsonFieldsSerializer.Serialize(topicsRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public async Task <IActionResult> CreateTopic( [ModelBinder(typeof(JsonModelBinder <TopicDto>))] Delta <TopicDto> topicDelta) { // Here we display the errors if the validation has failed at some point. if (!ModelState.IsValid) { return(Error()); } var newTopic = await _factory.InitializeAsync(); newTopic.Title = topicDelta.Dto.Title; newTopic.Body = topicDelta.Dto.Body; newTopic.SystemName = topicDelta.Dto.SystemName; await _topicService.InsertTopicAsync(newTopic); var topicsRootObject = new TopicsRootObject(); var topicDto = _dtoHelper.PrepareTopicDTO(newTopic); topicsRootObject.Topics.Add(topicDto); var json = JsonFieldsSerializer.Serialize(topicsRootObject, string.Empty); return(new RawJsonActionResult(json)); }
public IActionResult GetCategories(TopicsParametersModel parameters) { if (parameters.Limit < Constants.Configurations.MinLimit || parameters.Limit > Constants.Configurations.MaxLimit) { return(Error(HttpStatusCode.BadRequest, "limit", "Invalid limit parameter")); } if (parameters.Page < Constants.Configurations.DefaultPageValue) { return(Error(HttpStatusCode.BadRequest, "page", "Invalid page parameter")); } var allTopics = _topicApiService.GetTopics(parameters.Ids, parameters.CreatedAtMin, parameters.CreatedAtMax, parameters.UpdatedAtMin, parameters.UpdatedAtMax, parameters.Limit, parameters.Page, parameters.SinceId) .Where(c => StoreMappingService.Authorize(c)); IList <TopicDto> topicsAsDtos = allTopics.Select(topic => _dtoHelper.PrepareTopicToDTO(topic)).ToList(); var topicsRootObject = new TopicsRootObject { Topics = topicsAsDtos }; var json = JsonFieldsSerializer.Serialize(topicsRootObject, parameters.Fields); return(new RawJsonActionResult(json)); }
public async Task <IActionResult> GetTopics(TopicsParametersModel parameters) { var storeId = _storeContext.GetCurrentStore().Id; var topics = await _topicService.GetAllTopicsAsync(storeId); IList <TopicDto> topicsAsDtos = topics.Select(x => _dtoHelper.PrepareTopicDTO(x)).ToList(); var topicsRootObject = new TopicsRootObject { Topics = topicsAsDtos }; var json = JsonFieldsSerializer.Serialize(topicsRootObject, parameters.Fields); return(new RawJsonActionResult(json)); }
public async Task <IActionResult> GetOrderById(int id, string fields = "") { if (id <= 0) { return(Error(HttpStatusCode.BadRequest, "id", "invalid id")); } var topic = await _topicService.GetTopicByIdAsync(id); if (topic == null) { return(Error(HttpStatusCode.NotFound, "topic", "not found")); } var topicsRootObject = new TopicsRootObject(); var topicDto = _dtoHelper.PrepareTopicDTO(topic); topicsRootObject.Topics.Add(topicDto); var json = JsonFieldsSerializer.Serialize(topicsRootObject, fields); return(new RawJsonActionResult(json)); }