Пример #1
0
        public async Task <ScrapeJobDto> Create(ScrapeJobDto scrapeJob, ClaimsPrincipal principal)
        {
            if (scrapeJob != null && (!string.IsNullOrEmpty(scrapeJob.Url) && !string.IsNullOrEmpty(scrapeJob.Pattern)))
            {
                var entity = _mapper.Map <ScrapeJob>(scrapeJob);
                var idUser = await _userManager.GetUserAsync(principal);

                entity.IdentityUserForeignKey = idUser.Id;
                var highestId = _scrapeJobDomainService
                                .ReadUsersScrapeJobs(idUser.Id)
                                .OrderByDescending(j => j.UserSpecificId)
                                .FirstOrDefault()?.UserSpecificId;
                entity.UserSpecificId = (highestId ?? 0) + 1;
                entity.Enabled        = true;

                await _scrapeJobDomainService.AddAsync(entity);

                var success = await _unitOfWork.CommitAsync();

                if (success)
                {
                    await ExecuteScrapeJobAsync(entity);

                    return(_mapper.Map <ScrapeJobDto>(entity));
                }
            }

            return(null);
        }
Пример #2
0
        public async Task <IActionResult> PutScrapeJob(ScrapeJobDto scrapeJobDto)
        {
            var scrapeJob = await _scrapeJobService.Update(scrapeJobDto, User);

            if (scrapeJob != null)
            {
                return(Ok(scrapeJob));
            }

            return(BadRequest(new BadRequestError("Could not update ScrapeJob")));
        }
Пример #3
0
        public async Task <ScrapeJobDto> Update(ScrapeJobDto scrapeJobDto, ClaimsPrincipal principal)
        {
            var idUser = await _userManager.GetUserAsync(principal);

            var scrapeJob = GetScrapeJobByUserSpecificId(scrapeJobDto.Id, idUser.Id);

            if (scrapeJob != null)
            {
                await _scrapeJobDomainService.UpdateAsync(scrapeJob.Id, e => _mapper.Map(scrapeJobDto, e));

                var success = await _unitOfWork.CommitAsync();

                if (success)
                {
                    var updatedEntity = await _scrapeJobDomainService.GetAsync(scrapeJob.Id);

                    return(_mapper.Map <ScrapeJobDto>(updatedEntity));
                }
            }

            return(null);
        }