Ejemplo n.º 1
0
        public async Task <IActionResult> AddTag(AddTagDto tag)
        {
            var result = await _tagService.AddTag(tag);

            return(StatusCode(result, new
            {
                Message = "A new tag has been added"
            }));
        }
Ejemplo n.º 2
0
        public async Task <JsonResult> Add(AddTagDto model)
        {
            var result = await _tagAppService.Add(model);

            OutputModel outputModel = new OutputModel();

            outputModel.Data = result;
            return(new JsonResult(outputModel));
        }
Ejemplo n.º 3
0
        public async Task <ServiceResult> AddAsync([FromBody] AddTagDto add)
        {
            var validation = add.Validation();

            if (validation.Fail)
            {
                return(ServiceResult.Failed(validation.Msg));
            }
            return(await Task.FromResult(await _tagSvc.AddAsync(add)));
        }
Ejemplo n.º 4
0
        public async Task <ServiceResult> AddAsync(AddTagDto add)
        {
            var exist = await _tagRepo.Select.AnyAsync(c => c.Name == add.Name);

            if (exist)
            {
                return(await Task.FromResult(ServiceResult.Failed($"Name:{add.Name} 的文章标签已存在")));
            }
            var entity = Mapper.Map <TagEntity>(add);
            await _tagRepo.InsertAsync(entity);

            return(await Task.FromResult(ServiceResult.Successed("新增文章标签成功")));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> ChangeTagNameAsync(int id, AddTagDto addTagDto)
        {
            var tag = await tagManager.GetByIdAsync(id);

            if (tag != null)
            {
                tag.Name = addTagDto.Name;
                await tagManager.UpdateAsync(tag);

                return(NoContent());
            }
            else
            {
                return(BadRequest("Tag Bulunamadı"));
            }
        }
Ejemplo n.º 6
0
 public TagDto Add(AddTagDto dto)
 {
     return(_tagAppService.Add(dto));
 }
Ejemplo n.º 7
0
        public TagDto AddTag(int articleId, AddTagDto tag)
        {
            var t = _articleTagDomainService.AddTag(articleId, Mapper.Map <Tag>(tag));

            return(Mapper.Map <TagDto>(t));
        }
Ejemplo n.º 8
0
 public TagDto Add(AddTagDto dto)
 {
     var entity = _tagDomainService.Insert(Mapper.Map<Tag>(dto));
     return Mapper.Map<TagDto>(entity);
 }
Ejemplo n.º 9
0
 public IActionResult AddTag(int articleId, AddTagDto dto)
 {
     _articleAppService.AddTag(articleId, dto);
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 10
0
        public async Task <IActionResult> AddTagAsync(AddTagDto addTagDto)
        {
            await tagManager.AddAsync(mapper.Map <Tag>(addTagDto));

            return(Created("", addTagDto));
        }
Ejemplo n.º 11
0
        public async Task <CommandResult <Tag> > AddTag(AddTagDto tag)
        {
            if (tag is null)
            {
                return(new ErrorMessage
                {
                    ErrorCode = "CATALOG.TAG.ADD.NULL",
                    Message = "Please send a valid data",
                    StatusCode = System.Net.HttpStatusCode.BadRequest
                }.ToCommand <Tag>());
            }

            if (tag.TagName.IsNullOrEmpty())
            {
                return(new ErrorMessage
                {
                    ErrorCode = "CATALOG.TAG.ADD.NAME.EMPTY",
                    Message = "Please send a valid Tag name",
                    StatusCode = System.Net.HttpStatusCode.BadRequest
                }.ToCommand <Tag>());
            }


            var existedTags = from t in _tagsRepo.Table
                              where t.Name == tag.TagName && t.TagStatus == TagStatus.Ok
                              select t;

            if (existedTags.Any())
            {
                return(new ErrorMessage
                {
                    ErrorCode = "CATALOG.TAG.ADD.ALREADY.EXISTED",
                    Message = "The tag you are trying to add is already existed.",
                    StatusCode = System.Net.HttpStatusCode.BadRequest
                }.ToCommand <Tag>());
            }


            var imageSavingResult = await _imageSaver.SaveImageAsync(tag.Photo);

            if (!imageSavingResult.IsSuccessful)
            {
                return(new ErrorMessage
                {
                    ErrorCode = imageSavingResult.Error.ErrorCode,
                    Message = imageSavingResult.Error.Message,
                    StatusCode = imageSavingResult.Error.StatusCode
                }.ToCommand <Tag>());
            }


            var tagModel = new Tag
            {
                Name        = tag.TagName,
                Description = tag.Discreption,
                Photo       = new TagPhoto
                {
                    FilePath = imageSavingResult.Result.Path,
                    AdditionalInformation = QueryString.Create(new Dictionary <string, string>
                    {
                        { "Name", imageSavingResult.Result.Name.ToString() },
                        { "Version", "1" }
                    }).ToUriComponent(),
                    AddedAtUtc = DateTime.UtcNow,
                }
            };

            _tagsRepo.Add(tagModel);
            await _tagsRepo.SaveChangesAsync();

            return(new CommandResult <Tag>(tagModel));
        }
Ejemplo n.º 12
0
 public TagDto AddTag(int articleId, [FromBody] AddTagDto dto)
 {
     return(_articleAppService.AddTag(articleId, dto));
 }
Ejemplo n.º 13
0
        public async Task <IActionResult> AddTag(AddTagDto tag)
        {
            var result = await _tagAdder.AddTag(tag);

            return(StatusCode(result));
        }
Ejemplo n.º 14
0
 public async Task <Result> Add(AddTagDto dto)
 {
     return(await _tagService.Add(_mapper.Map <Tag>(dto)));
 }