Exemple #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());
        }
        protected IActionResult CreateResource <TCreateDto, TGetDto>(TCreateDto createDto)
            where TCreateDto : ICreateDto <TEntity>
            where TGetDto : IGetDto <TEntity>
        {
            if (createDto == null)
            {
                return(BadRequest(InvalidData()));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(InvalidData())); // TODO: -- 400 missing required fields, consider mentioning which
            }
            var resource = Map <TEntity>(createDto);
            var result   = ResourceDataService.AreRelationshipsValid(resource);

            if (!result.IsValid)
            {
                return(NotFound(ParentNotFound(result.NotFoundParentId)));
            }
            ResourceDataService.Create(resource);
            ResourceDataService.SaveChanges();
            CreatedResource = resource;
            var resourceToReturn = Map <TGetDto>(resource);

            return(CreatedAtRoute(_getResourceRouteName, new { id = resourceToReturn.Id }, resourceToReturn));
        }
        //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)));
        }
        protected IActionResult DeleteResource(Guid id)
        {
            var resource = ResourceDataService.Get(id);

            if (resource == null)
            {
                return(NotFound(ResourceNotFound(id.ToString())));
            }
            ResourceDataService.Delete(resource);
            ResourceDataService.SaveChanges();
            return(NoContent());
        }
Exemple #5
0
        public new IActionResult DeleteResource(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())));
            }

            CancelExecution(id);
            ResourceDataService.Delete(resource);
            ResourceDataService.SaveChanges();
            return(NoContent());
        }
Exemple #6
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);
        }