public IActionResult GetObjectDefinitions()
        {
            IActionResult result;

            ServiceModels.ObjectDefinitions response = new ServiceModels.ObjectDefinitions();
            string rootUrl = Request.GetRootUrl();

            response.AddLink("add", string.Concat(rootUrl, "/objecttypes/definitions"), null);
            int organisationID = User.GetOrganisationID();
            List <Model.ObjectDefinition> objectDefinitions = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinitions(organisationID);

            response.PageInfo = Request.GetPageInfo(objectDefinitions.Count);
            int endIndex = response.PageInfo.StartIndex + response.PageInfo.ItemsCount;

            for (int index = response.PageInfo.StartIndex; index < endIndex; index++)
            {
                ServiceModels.ObjectDefinition objectDefinition = new ServiceModels.ObjectDefinition(objectDefinitions[index]);
                if (organisationID == 0)
                {
                    objectDefinition.AddSelfLink(string.Concat(rootUrl, "/objecttypes/definitions/", objectDefinition.ObjectDefinitionID), true, true);
                }
                else
                {
                    objectDefinition.AddSelfLink(string.Concat(rootUrl, "/objecttypes/definitions/", objectDefinition.ObjectDefinitionID), objectDefinitions[index].OrganisationID.HasValue, objectDefinitions[index].OrganisationID.HasValue);
                }
                response.Add(objectDefinition);
            }
            result = Request.GetObjectResult(response);
            return(result);
        }
        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);
        }
        public IActionResult GetObjectDefinition(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
                {
                    ServiceModels.ObjectDefinition response = new ServiceModels.ObjectDefinition(objectDefinition);
                    string rootUrl = Request.GetRootUrl();
                    if (organisationID == 0)
                    {
                        response.AddSelfLink(string.Concat(rootUrl, "/objecttypes/definitions/", response.ObjectDefinitionID), true, true);
                    }
                    else
                    {
                        response.AddSelfLink(string.Concat(rootUrl, "/objecttypes/definitions/", response.ObjectDefinitionID), objectDefinition.OrganisationID.HasValue, objectDefinition.OrganisationID.HasValue);
                    }
                    result = Request.GetObjectResult(response);
                }
            }
            else
            {
                result = new BadRequestResult();
            }
            return(result);
        }
        private IActionResult AddObjectDefinition(ServiceModels.ObjectDefinition objectDefinition)
        {
            IActionResult result;

            if (objectDefinition == null)
            {
                result = new BadRequestResult();
            }
            else
            {
                ResourceCreated        response = new ResourceCreated();
                string                 rootUrl  = Request.GetRootUrl();
                Model.ObjectDefinition item     = objectDefinition.ToModel();
                item.OrganisationID = User.GetOrganisationID();
                try
                {
                    BusinessLogicFactory.ObjectDefinitions.SaveObjectDefinition(item, Model.TObjectState.Add);
                    response.ID = StringUtils.GuidEncode(item.ObjectDefinitionID);
                    response.AddSelfLink(string.Concat(rootUrl, "/objecttypes/definitions/", response.ID), false, false);
                    result = Request.GetObjectResult(response, System.Net.HttpStatusCode.Created);
                }
                catch (ConflictException)
                {
                    result = new StatusCodeResult((int)HttpStatusCode.Conflict);
                }
            }
            return(result);
        }
 public IActionResult GetObjectDefinition(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
         {
             ServiceModels.ObjectDefinition response = new ServiceModels.ObjectDefinition(objectDefinition);
             string rootUrl = Request.GetRootUrl();
             if (organisationID == 0)
                 response.AddSelfLink(string.Concat(rootUrl, "/objecttypes/definitions/", response.ObjectDefinitionID), true, true);
             else
                 response.AddSelfLink(string.Concat(rootUrl, "/objecttypes/definitions/", response.ObjectDefinitionID), objectDefinition.OrganisationID.HasValue, objectDefinition.OrganisationID.HasValue);
             result = Request.GetObjectResult(response);
         }
     }
     else
         result = new BadRequestResult();
     return result;
 }
 public IActionResult GetObjectDefinitions()
 {
     IActionResult result;
     ServiceModels.ObjectDefinitions response = new ServiceModels.ObjectDefinitions();
     string rootUrl = Request.GetRootUrl();
     response.AddLink("add", string.Concat(rootUrl, "/objecttypes/definitions"), null);
     int organisationID = User.GetOrganisationID();
     List<Model.ObjectDefinition> objectDefinitions = BusinessLogicFactory.ObjectDefinitions.GetObjectDefinitions(organisationID);
     response.PageInfo = Request.GetPageInfo(objectDefinitions.Count);
     int endIndex = response.PageInfo.StartIndex + response.PageInfo.ItemsCount;
     for (int index = response.PageInfo.StartIndex; index < endIndex; index++)
     {
         ServiceModels.ObjectDefinition objectDefinition = new ServiceModels.ObjectDefinition(objectDefinitions[index]);
         if (organisationID == 0)
             objectDefinition.AddSelfLink(string.Concat(rootUrl, "/objecttypes/definitions/", objectDefinition.ObjectDefinitionID), true, true);
         else
             objectDefinition.AddSelfLink(string.Concat(rootUrl, "/objecttypes/definitions/", objectDefinition.ObjectDefinitionID), objectDefinitions[index].OrganisationID.HasValue, objectDefinitions[index].OrganisationID.HasValue);
         response.Add(objectDefinition);
     }
     result = Request.GetObjectResult(response);
     return result;
 }