示例#1
0
        public async Task <Guid> CreateAsync(Guid teamId, TicketDto ticketDto)
        {
            var ticket = _mapper.Map <Ticket>(ticketDto);
            await _tagService.AddAsync(ticketDto.Tags);

            ticket.CreationDate = DateTime.UtcNow;

            var id = await _unitOfWork.Tickets.CreateAsync(teamId, ticket);

            _logger.LogInformation($"Ticket with name {ticket.Name} was successfully created");

            return(id);
        }
示例#2
0
        public async Task <IActionResult> CreateTagAsync([FromBody] string model)
        {
            var result = await _service.AddAsync(model);

            result.Url = this.Url.RouteUrl("GetTagById", new { id = result.Id });
            return(CreatedAtRoute("GetTagById", new { id = result.Id }, result));
        }
        private async Task <List <int> > CreateNonExistingTags(List <TagModel> tags)
        {
            List <int> tagIds = new List <int>();

            foreach (var tag in tags)
            {
                if (tag.Id == null)
                {
                    TagModel wordToAdd = new TagModel
                    {
                        Value = tag.Value
                    };
                    tag.Id = await tagService.AddAsync(wordToAdd);

                    if (tag.Id == -1)
                    {
                        Tag tagToCheck = await tagService.GetFirstTagByNameAsync(tag.Value);

                        tag.Id = tagToCheck.Id;
                    }
                }
                tagIds.Add(tag.Id ?? default(int));
            }
            return(tagIds);
        }
        public async Task <IActionResult> Add(AddTagViewModel model)
        {
            if (!string.IsNullOrWhiteSpace(model.Name) && await tagService.ExistsAsync(model.Name))
            {
                ModelState.AddModelError(nameof(model.Name), "Tag with the same name already exists.");
            }

            if (!ModelState.IsValid)
            {
                model.Destinations = await GetDestinations();

                return(View(model));
            }

            var id = await tagService.AddAsync(model.Name, model.SelectedDestinations);

            if (id < 1)
            {
                ModelState.AddModelError(string.Empty, "Save failed.");
                model.Destinations = await GetDestinations();

                return(View(model));
            }

            return(RedirectToAction(nameof(Add)));
        }
示例#5
0
 public virtual async Task <JsonResult> Add(Tag model)
 {
     if (!ModelState.IsValid)
     {
         return(Json(new { IsSuccessful = false, Message = ModelState.GetModelError() }));
     }
     return(Json(await _tagSrv.AddAsync(model)));
 }
示例#6
0
        public async Task <IActionResult> Create([FromBody, CustomizeValidator] TagToAdd tag, CancellationToken cancellationToken = default)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _tagService.AddAsync(tag, cancellationToken);

            return(result.IsError ? BadRequest(result.Message) : (IActionResult)Ok(result.Data));
        }
示例#7
0
        public async Task AddTagFromChargeAsync(int chargeId, Tag tag)
        {
            var newTag = await _tagService.AddAsync(tag);

            await _chargeTagRelationService.AddAsync(chargeId, newTag.Id);

            await _noteService.AddTagHistoryNoteAsync(chargeId, tag);

            await _chargeService.SetUpdatedAsync(chargeId);
        }
示例#8
0
        public async Task <ActionResult> AddAsync([FromBody] TagBO model)
        {
            var tag = await _tagService
                      .AddAsync(model);

            if (tag != null)
            {
                return(CreatedAtAction("Get", new { id = tag.Id }, tag));
            }

            return(BadRequest());
        }
示例#9
0
        public void Add_AddTag_IfDataExists()
        {
            _unitOfWorkMock
            .Setup(unitOfWork => unitOfWork.Tags.GetAll())
            .Returns(new List <Tag>().AsQueryable());

            _sut.AddAsync(new List <string> {
                "tag-stub"
            });

            _unitOfWorkMock.Verify(unitOfWork => unitOfWork.Tags.CreateAsync(It.IsAny <Tag>()), Times.Once);
        }
        public async Task <IActionResult> Add([FromBody] AddTagRequest request, [FromRoute] int accountId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }

            var response = await _tagService.AddAsync(request, accountId);

            if (!response.IsValid)
            {
                return(BadRequest(response.Message));
            }
            return(Ok(response));
        }
示例#11
0
        public async Task SeedAsync()
        {
            _logger.LogTrace("Initializing data...");
            _logger.LogCritical("critikal");
            var tasks = new List <Task>();

            for (int i = 1; i < 11; i++)
            {
                var userId   = Guid.NewGuid();
                var userName = $"user{i}";
                await _userService.RegisterAsync(userId, $"{userName}@gmail.com", userName, "password");
            }
            for (int i = 1; i < 4; i++)
            {
                var userId   = Guid.NewGuid();
                var userName = $"admin{i}";
                await _userService.RegisterAsync(userId, $"{userName}@gmail.com", userName, "password");
            }
            tasks.Add(_tagService.AddAsync("test", Guid.NewGuid(), "One"));
            await Task.WhenAll(tasks);

            _logger.LogTrace("Data was initialized");
        }
示例#12
0
        public async Task <IActionResult> CreateTag([FromBody] TagCreateDto model)
        {
            var result = await _tagService.AddAsync(model);

            return(CreatedAtAction(nameof(GetTagById), new { id = result.Id }, null));
        }
示例#13
0
 public async Task <IActionResult> AddAsync([FromBody] Tag tag)
 {
     return(ApiOk(await TagService.AddAsync(tag)));
 }