Пример #1
0
        public async Task <IHttpActionResult> Cancel([FromODataUri] String key, ODataActionParameters parameters)
        {
            var declaringType = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
            var fn            = String.Format("{0}:{1}",
                                              declaringType.Namespace,
                                              declaringType.Name);

            try
            {
                Debug.WriteLine(fn);

                var identity = CurrentUserDataProvider.GetIdentity(TenantId);

                var permissionId = CreatePermissionId("CanCancel");
                if (!identity.Permissions.Contains(permissionId))
                {
                    return(StatusCode(HttpStatusCode.Forbidden));
                }

                var entityUri        = new Uri(key);
                var entity           = LoadEntity(new DefaultAuthenticationProvider(), entityUri);
                var lifeCycleManager = new LifeCycleManager(new DefaultAuthenticationProvider(), ExtractTypeFromUriString(key));
                lifeCycleManager.Cancel(entityUri, entity, identity.Tid);

                return(Ok());
            }
            catch (UriFormatException e)
            {
                return(BadRequest("Invalid id (Id should be a valid URI)"));
            }
            catch (HttpRequestException e)
            {
                return(BadRequest("Loading entity from passed Uri failed (Either not found or not authorized)"));
            }
            catch (InvalidOperationException e)
            {
                return(BadRequest("Changing state with 'Cancel' condition not possible"));
            }
            catch (Exception e)
            {
                Debug.WriteLine(String.Format("{0}: {1}\r\n{2}", e.Source, e.Message, e.StackTrace));
                throw;
            }
        }
        public async Task<IHttpActionResult> Cancel([FromODataUri] String key, ODataActionParameters parameters)
        {
            var declaringType = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
            var fn = String.Format("{0}:{1}",
                declaringType.Namespace,
                declaringType.Name);

            try
            {
                Debug.WriteLine(fn);

                var identity = CurrentUserDataProvider.GetIdentity(TenantId);

                var permissionId = CreatePermissionId("CanCancel");
                if (!identity.Permissions.Contains(permissionId))
                {
                    return StatusCode(HttpStatusCode.Forbidden);
                }

                var entityUri = new Uri(key);
                var entity = LoadEntity(new DefaultAuthenticationProvider(), entityUri);
                var lifeCycleManager = new LifeCycleManager(new DefaultAuthenticationProvider(), ExtractTypeFromUriString(key));
                lifeCycleManager.Cancel(entityUri, entity, identity.Tid);

                return Ok();
            }
            catch (UriFormatException e)
            {
                return BadRequest("Invalid id (Id should be a valid URI)");
            }
            catch (HttpRequestException e)
            {
                return BadRequest("Loading entity from passed Uri failed (Either not found or not authorized)");
            }
            catch (InvalidOperationException e)
            {
                return BadRequest("Changing state with 'Cancel' condition not possible");
            }
            catch (Exception e)
            {
                Debug.WriteLine(String.Format("{0}: {1}\r\n{2}", e.Source, e.Message, e.StackTrace));
                throw;
            }
        }