예제 #1
0
        public IActionResult CancelExecution(Guid id)
        {
            var resource = ResourceDataService.Get(id);

            if (resource == null || resource.SubscriberId != User.Claims.First(claim => claim.Type == JwtClaimTypes.Subject).Value)
            {
                return(NotFound(ResourceNotFound(id.ToString())));
            }
            if (resource.Status == Status.Enqueued || resource.Status == Status.InProgress)
            {
                //if(resource.InnerJobId != null)
                //    BackgroundJob.Delete(resource.InnerJobId);

                //BackgroundJob.Delete(resource.JobId);

                ExecutionLogger.SetExecutionId(id);
                ExecutionLogger.Error("Execution canceled by the user.");

                resource.Status     = Status.Canceled;
                resource.FinishTime = DateTime.Now;
                resource.CancelJob  = true;
                ResourceDataService.Update(resource);
                ResourceDataService.SaveChanges();
            }
            return(NoContent());
        }
예제 #2
0
        //protected IActionResult GetResources<TGetDto>(BaseResourceParameters baseResourceParameters,
        //    FilterByIdsParameter<TIdentifier> filterByIdsParameters) where TGetDto : IGetDto<TEntity, TIdentifier>
        //{
        //    return Ok(Map<IEnumerable<TGetDto>>(ResourceDataService.GetManyFilter(baseResourceParameters, filterByIdsParameters)));
        //}

        protected IActionResult UpdateResource <TUpdateDto, TGetDto>(Guid id, TUpdateDto updateDto)
            where TUpdateDto : IUpdateDto <TEntity>
            where TGetDto : IGetDto <TEntity>
        {
            var resource = ResourceDataService.Get(id);

            if (resource == null)
            {
                return(NotFound(ResourceNotFound(id.ToString())));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(InvalidData()));
            }
            Map(updateDto, resource);
            var result = ResourceDataService.AreRelationshipsValid(resource);

            if (!result.IsValid)
            {
                return(NotFound(ParentNotFound(result.NotFoundParentId)));
            }
            ResourceDataService.Update(resource);
            ResourceDataService.SaveChanges();
            return(Ok(Map <TGetDto>(resource)));
        }
예제 #3
0
        public IActionResult CreateResource([FromBody] DiscreteLogarithmCreateDto createDto)
        {
            var result = base.CreateResource <DiscreteLogarithmCreateDto, DiscreteLogarithmGetDto>(createDto);

            if (CreatedResource == null)
            {
                return(result);
            }

            if (User.Identity.IsAuthenticated)
            {
                CreatedResource.SubscriberId = User.Claims.First(claim => claim.Type == JwtClaimTypes.Subject).Value;
            }

            CreatedResource.JobId = CreatedResource.StartJobService();
            ResourceDataService.Update(CreatedResource);
            ResourceDataService.SaveChanges();

            ExecutionLogger.SetExecutionId(CreatedResource.Id);
            ExecutionLogger.Info("Enqueued for execution.");

            return(result);
        }