コード例 #1
0
        public async Task <IActionResult> LoadDb()
        {
            var ResultOK  = new Microsoft.AspNetCore.Mvc.StatusCodeResult(200); //Ok
            var ResultNOK = new Microsoft.AspNetCore.Mvc.StatusCodeResult(500); //NOk

            await AddSomeData();

            return(ResultOK);
        }
        public async Task <ActionResult> BuildActionResultAsync()
        {
            var result = new Microsoft.AspNetCore.Mvc.StatusCodeResult(StatusCode);

            return(result);
        }
コード例 #3
0
        public IActionResult AddSubscription(string clientID, string definitionID, string instanceID, [FromBody] ServiceModels.Subscription subscription)
        {
            IActionResult result;
            if (subscription != null)
            {
                Model.Subscription item = subscription.ToModel(Request, clientID, definitionID, instanceID);
                item.OrganisationID = User.GetOrganisationID();
                item.SubscriptionID = Guid.NewGuid();

                if (!ExistingSubscriptionMatches(item))
                {
                    BusinessLogicFactory.Subscriptions.SaveSubscription(item, Model.TObjectState.Add);

                    ServiceModels.ResourceCreated response = new ServiceModels.ResourceCreated();
                    response.ID = StringUtils.GuidEncode(item.SubscriptionID);
                    string rootUrl = Request.GetRootUrl();
                    response.AddSelfLink(string.Concat(rootUrl, "/subscriptions/", response.ID), false, false);
                    result = Request.GetObjectResult(response, System.Net.HttpStatusCode.Created);
                }
                else
                {
                    result = new StatusCodeResult((int)System.Net.HttpStatusCode.Conflict);
                }
            }
            else
            {
                result = new BadRequestResult();
            }
            return result;
        }
コード例 #4
0
        public IActionResult UpdateSubscription(string subscriptionID, [FromBody] ServiceModels.Subscription subscription)
        {
            IActionResult result;
            Guid subscriptionIDGuid;
            if (StringUtils.GuidTryDecode(subscriptionID, out subscriptionIDGuid))
            {
                Model.Subscription subscriptionToUpdate = BusinessLogicFactory.Subscriptions.GetSubscription(subscriptionIDGuid);
                if (subscriptionToUpdate == null)
                    result = new NotFoundResult();
                else
                {
                    subscription.UpdateModel(subscriptionToUpdate);

                    if (!ExistingSubscriptionMatches(subscriptionToUpdate))
                    {
                        BusinessLogicFactory.Subscriptions.SaveSubscription(subscriptionToUpdate, TObjectState.Update);
                        result = new NoContentResult();
                    }
                    else
                    {
                        result = new StatusCodeResult((int)System.Net.HttpStatusCode.Conflict);
                    }
                }
            }
            else
            {
                result = new BadRequestResult();
            }
            return result;
        }
コード例 #5
0
 private IActionResult AddObjectDefinitions(ServiceModels.ObjectDefinitions objectDefinitions)
 {
     IActionResult result;
     if (objectDefinitions == null || objectDefinitions.Items == null)
         result = new BadRequestResult();
     else
     {
         List<Model.ObjectDefinition> items = new List<Model.ObjectDefinition>();
         foreach (ServiceModels.ObjectDefinition item in objectDefinitions.Items)
         {
             Model.ObjectDefinition objectDefinition = item.ToModel();
             objectDefinition.OrganisationID = User.GetOrganisationID();
             items.Add(objectDefinition);
         }
         try
         {
             BusinessLogicFactory.ObjectDefinitions.SaveObjectDefinitions(items, Model.TObjectState.Add);
             string rootUrl = Request.GetRootUrl();
             ResourcesCreated response = new ResourcesCreated();
             foreach (Model.ObjectDefinition item in items)
             {
                 ResourceCreated resourceCreated = new ResourceCreated();
                 resourceCreated.ID = StringUtils.GuidEncode(item.ObjectDefinitionID);
                 resourceCreated.AddSelfLink(string.Concat(rootUrl, "/objecttypes/definitions/", resourceCreated.ID), false, false);
                 response.Add(resourceCreated);
             }
             result = Request.GetObjectResult(response, System.Net.HttpStatusCode.Created);
         }
         catch (ConflictException)
         {
             result = new StatusCodeResult((int)HttpStatusCode.Conflict);
         }
     }
     return result;
 }
コード例 #6
0
 public IActionResult UpdateObjectDefinition(string id, [FromBody] ServiceModels.ObjectDefinition objectDefinition)
 {
     IActionResult result;
     Guid objectDefinitionID;
     if (StringUtils.GuidTryDecode(id, out objectDefinitionID))
     {
         int organisationID = User.GetOrganisationID();
         Model.ObjectDefinition existingObjectDefinition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, objectDefinitionID);
         if (existingObjectDefinition == null)
             result = new NotFoundResult();
         else
         {
             if (!existingObjectDefinition.OrganisationID.HasValue && (organisationID != 0))
                 result = new StatusCodeResult((int)System.Net.HttpStatusCode.Forbidden);
             else
             {
                 Model.ObjectDefinition updatedObjectDefinition = objectDefinition.ToModel();
                 updatedObjectDefinition.OrganisationID = User.GetOrganisationID();
                 BusinessLogicFactory.ObjectDefinitions.SaveObjectDefinition(updatedObjectDefinition, Model.TObjectState.Update);
                 result = new NoContentResult();
             }
         }
     }
     else
         result = new BadRequestResult();
     return result;
 }
コード例 #7
0
 public IActionResult RemoveObjectDefinition(string id)
 {
     IActionResult result;
     Guid objectDefinitionID;
     if (StringUtils.GuidTryDecode(id, out objectDefinitionID))
     {
         int organisationID = User.GetOrganisationID();
         Model.ObjectDefinition objectDefinition = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinition(organisationID, objectDefinitionID);
         if (objectDefinition == null)
             result = new NotFoundResult();
         else
         {
             if (!objectDefinition.OrganisationID.HasValue && (organisationID != 0))
                 result = new StatusCodeResult((int)System.Net.HttpStatusCode.Forbidden);
             else
             {
                 BusinessLogicFactory.ObjectDefinitions.SaveObjectDefinition(objectDefinition, Model.TObjectState.Delete);
                 result = new NoContentResult();
             }
         }
     }
     else
         result = new BadRequestResult();
     return result;
 }