public async Task <IActionResult> Create([FromBody] TagInputModel tagData)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState.ToDictionary(x => x.Key, x => x.Value.Errors)));
            }

            var tag = new Tag
            {
                Name           = tagData.Name,
                NormalizedName = tagData.Name.ToUpper(),
                CreatedOn      = DateTime.UtcNow,
                EditedOn       = DateTime.UtcNow,
                IsActive       = true
            };

            try
            {
                await this.tagService.Create(tag);
            }
            catch (Exception e)
            {
                this.logger.LogError(e.Message);
                this.logger.LogInformation(e.StackTrace);
                return(this.BadRequest("An error occurred while trying to create a tag!"));
            }

            return(this.Ok("Tag created successfully!"));
        }
        public async Task <IActionResult> EditPost(string id, [FromBody] TagInputModel tagInput)
        {
            bool isIdCorrect = int.TryParse(id, out int tagId);

            if (!isIdCorrect)
            {
                return(this.NotFound("Tag does not exist!"));
            }

            var tag = this.tagService.GetById(tagId, true);

            if (tag == null)
            {
                return(this.NotFound("Tag does not exist!"));
            }

            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState.ToDictionary(x => x.Key, x => x.Value.Errors)));
            }

            try
            {
                await this.tagService.Update(tag, tagInput);
            }
            catch (Exception e)
            {
                this.logger.LogError(e.Message);
                this.logger.LogInformation(e.StackTrace);
                return(this.BadRequest("An error occurred while trying to edit tag!"));
            }

            return(this.Ok("Successfully edited tag!"));
        }
Exemple #3
0
 public TagDTO ConvertTagInputModelToTagDTO(TagInputModel tagmodel)
 {
     return(new TagDTO()
     {
         ID = tagmodel.ID,
         Name = tagmodel.Name,
     });
 }
Exemple #4
0
        public ActionResult <int> PostTag([FromBody] TagInputModel tagModel)
        {
            if (string.IsNullOrWhiteSpace(tagModel.Name))
            {
                return(BadRequest("Введите название тега"));
            }
            Mapper           mapper = new Mapper();
            TagDTO           tagDto = mapper.ConvertTagInputModelToTagDTO(tagModel);
            AuthorDataAccess tag    = new AuthorDataAccess();

            return(Ok(tag.AddTag(tagDto)));
        }
Exemple #5
0
        public ActionResult <int> PutTagById([FromBody] TagInputModel tagModel)
        {
            Mapper           mapper = new Mapper();
            TagDTO           tagDto = mapper.ConvertTagInputModelToTagDTO(tagModel);
            AuthorDataAccess tags   = new AuthorDataAccess();
            var tag = tags.GetTagById(tagModel.ID);

            if (tag == null)
            {
                return(BadRequest("Тега не существует"));
            }
            if (string.IsNullOrWhiteSpace(tagModel.Name))
            {
                return(BadRequest("Введите название тега"));
            }
            tags.UpdateTagById(tagDto);
            return(Ok(tagModel.ID));
        }
        public async Task <IActionResult> Edit(TagInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values));
            }

            try
            {
                var userId     = base.GetUserIdFromAuthorizeHeader();
                var tagDbModel = mapper.Map <Tag>(model);
                var editedTag  = await tagService.Edit <TagDTO>(tagDbModel, userId);

                return(Ok(editedTag));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemple #7
0
        public async Task <IActionResult> Post([FromBody] TagInputModel tag)
        {
            await _commandsDispatcher.ExecuteAsync(new TweetsRefreshCommandContext(tag.Value, _tweetsSettings.TweetsCount, _tweetsSettings.IsSaveHistory, _tweetsSettings.ResultType));

            return(Ok());
        }