// POST: api/Core.svc/CalloutDefinitions
        public async Task<IHttpActionResult> Post(CalloutDefinition calloutDefinition)
        {
            var declaringType = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
            var fn = String.Format("{0}:{1}",
                declaringType.Namespace,
                declaringType.Name);

            if (!ModelState.IsValid)
            {
                Debug.WriteLine("CalloutDefinition to be created has invalid ModelState.");
                return BadRequest(ModelState);
            }
            try
            {
                Debug.WriteLine(fn);

                var identity = CurrentUserDataProvider.GetIdentity(TenantId);

                var permissionId = CreatePermissionId("CanCreate");
                if (!identity.Permissions.Contains(permissionId))
                {
                    return StatusCode(HttpStatusCode.Forbidden);
                }
                if (null == calloutDefinition)
                {
                    var errorMsg = "CalloutDefinition to be created contains invalid data.";
                    Debug.WriteLine(errorMsg);
                    return BadRequest(errorMsg);
                }
                Debug.WriteLine("Saving new CalloutDefinition...");

                var calloutDefinitionEntity = new CalloutDefinition()
                {
                    Created = DateTimeOffset.Now,
                    CreatedBy = identity.Username,
                    CalloutType = calloutDefinition.CalloutType,
                    Tid = identity.Tid,
                    TenantId = calloutDefinition.TenantId,
                    EntityType = calloutDefinition.EntityType,
                    EntityId = calloutDefinition.EntityId,
                    Condition = calloutDefinition.Condition,
                    Parameters = calloutDefinition.Parameters
                };
                calloutDefinitionEntity = db.CalloutDefinitions.Add(calloutDefinitionEntity);
                db.SaveChanges();
                Debug.WriteLine("Saved CalloutDefinition with id '{0}'", calloutDefinitionEntity.Id);
                return ResponseMessage(ODataControllerHelper.ResponseCreated(this, calloutDefinitionEntity));
            }
            catch (Exception e)
            {
                Debug.WriteLine(String.Format("{0}: {1}\r\n{2}", e.Source, e.Message, e.StackTrace));
                throw;
            }
        }
        // PUT: api/Core.svc/CalloutDefinitions(5)
        public async Task<IHttpActionResult> Put([FromODataUri] int key, CalloutDefinition calloutDefinition)
        {
            var declaringType = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
            var fn = String.Format("{0}:{1}",
                declaringType.Namespace,
                declaringType.Name);

            if (!ModelState.IsValid)
            {
                Debug.WriteLine("CalloutDefinition to be updated with id '{0}' has invalid ModelState.", key);
                return BadRequest(ModelState);
            }

            if (key != calloutDefinition.Id)
            {
                return BadRequest();
            }

            try
            {
                Debug.WriteLine(fn);

                var identity = CurrentUserDataProvider.GetIdentity(TenantId);

                var permissionId = CreatePermissionId("CanUpdate");
                if (!identity.Permissions.Contains(permissionId))
                {
                    return StatusCode(HttpStatusCode.Forbidden);
                }
                var original = db.CalloutDefinitions.Find(calloutDefinition.Id);
                if (null == original)
                {
                    return StatusCode(HttpStatusCode.NotFound);
                }
                if (!CurrentUserDataProvider.IsEntityOfUser(identity.Username, identity.Tid, calloutDefinition))
                {
                    return StatusCode(HttpStatusCode.Forbidden);
                }
                calloutDefinition.Created = original.Created;
                calloutDefinition.CreatedBy = original.CreatedBy;
                calloutDefinition.Modified = DateTimeOffset.Now;
                calloutDefinition.ModifiedBy = identity.Username;
                calloutDefinition.Tid = original.Tid;
                db.CalloutDefinitions.Attach(calloutDefinition);
                db.Entry(calloutDefinition).State = EntityState.Modified;
                db.SaveChanges();
                Debug.WriteLine("CalloutDefinition with id '{0}' updated", key);
                return Ok<CalloutDefinition>(calloutDefinition);
            }
            catch (Exception e)
            {
                Debug.WriteLine(String.Format("{0}: {1}\r\n{2}", e.Source, e.Message, e.StackTrace));
                throw;
            }
        }