Пример #1
0
        public async Task <ActionResult> Undelete(int instanceOwnerPartyId, Guid instanceGuid)
        {
            string instanceId = $"{instanceOwnerPartyId}/{instanceGuid}";

            Instance instance;

            try
            {
                instance = await _instanceRepository.GetOne(instanceId, instanceOwnerPartyId);
            }
            catch (DocumentClientException dce)
            {
                if (dce.Error.Code.Equals("NotFound"))
                {
                    return(NotFound($"Didn't find the object that should be restored with instanceId={instanceId}"));
                }

                return(StatusCode(500, $"Unknown database exception in restore: {dce}"));
            }

            if (instance.Status.HardDeleted.HasValue)
            {
                return(BadRequest("Instance was permanently deleted and cannot be restored."));
            }
            else if (instance.Status.SoftDeleted.HasValue)
            {
                instance.LastChangedBy      = User.GetUserOrOrgId();
                instance.LastChanged        = DateTime.UtcNow;
                instance.Status.SoftDeleted = null;

                InstanceEvent instanceEvent = new InstanceEvent
                {
                    Created              = DateTime.UtcNow,
                    EventType            = InstanceEventType.Undeleted.ToString(),
                    InstanceId           = instance.Id,
                    InstanceOwnerPartyId = instance.InstanceOwner.PartyId,
                    User = new PlatformUser
                    {
                        UserId = User.GetUserIdAsInt(),
                        AuthenticationLevel = User.GetAuthenticationLevel(),
                        OrgId = User.GetOrg(),
                    }
                };

                try
                {
                    await _instanceRepository.Update(instance);

                    await _instanceEventRepository.InsertInstanceEvent(instanceEvent);

                    return(Ok(true));
                }
                catch (Exception e)
                {
                    return(StatusCode(500, $"Unknown exception in restore: {e}"));
                }
            }

            return(Ok(true));
        }
Пример #2
0
        public async Task <ActionResult> Undelete(int instanceOwnerId, Guid instanceGuid)
        {
            string instanceId = $"{instanceOwnerId}/{instanceGuid}";

            Instance instance;

            try
            {
                instance = await _instanceRepository.GetOne(instanceId, instanceOwnerId);
            }
            catch (DocumentClientException dce)
            {
                if (dce.Error.Code.Equals("NotFound"))
                {
                    return(NotFound($"Didn't find the object that should be restored with instanceId={instanceId}"));
                }

                return(StatusCode(500, $"Unknown database exception in restore: {dce}"));
            }

            if (instance.InstanceState.IsMarkedForHardDelete)
            {
                return(BadRequest("Instance was permanently deleted and cannot be restored."));
            }
            else if (instance.InstanceState.IsDeleted)
            {
                instance.InstanceState.IsDeleted       = false;
                instance.LastChangedBy                 = User.Identity.Name;
                instance.LastChangedDateTime           = DateTime.UtcNow;
                instance.InstanceState.DeletedDateTime = null;

                InstanceEvent instanceEvent = new InstanceEvent
                {
                    CreatedDateTime     = DateTime.UtcNow,
                    AuthenticationLevel = 0, // update when authentication is turned on
                    EventType           = InstanceEventType.Undeleted.ToString(),
                    InstanceId          = instance.Id,
                    InstanceOwnerId     = instance.InstanceOwnerId.ToString(),
                    UserId = 0, // update when authentication is turned on
                };

                try
                {
                    await _instanceRepository.Update(instance);

                    await _instanceEventRepository.InsertInstanceEvent(instanceEvent);

                    return(Ok(true));
                }
                catch (Exception e)
                {
                    return(StatusCode(500, $"Unknown exception in restore: {e}"));
                }

                // generate instance event 'Undeleted'
            }

            return(Ok(true));
        }
Пример #3
0
        public async Task <ActionResult> Undelete(int instanceOwnerPartyId, Guid instanceGuid)
        {
            Instance instance;

            instance = await _instanceRepository.GetOne(instanceOwnerPartyId, instanceGuid);

            if (instance == null)
            {
                return(NotFound($"Didn't find the object that should be restored with instanceId={instanceOwnerPartyId}/{instanceGuid}"));
            }

            if (instance.Status.IsHardDeleted)
            {
                return(NotFound("Instance was permanently deleted and cannot be restored."));
            }
            else if (instance.Status.IsSoftDeleted)
            {
                instance.LastChangedBy        = User.GetUserOrOrgId();
                instance.LastChanged          = DateTime.UtcNow;
                instance.Status.IsSoftDeleted = false;
                instance.Status.SoftDeleted   = null;

                InstanceEvent instanceEvent = new InstanceEvent
                {
                    Created              = DateTime.UtcNow,
                    EventType            = InstanceEventType.Undeleted.ToString(),
                    InstanceId           = instance.Id,
                    InstanceOwnerPartyId = instance.InstanceOwner.PartyId,
                    User = new PlatformUser
                    {
                        UserId = User.GetUserIdAsInt(),
                        AuthenticationLevel = User.GetAuthenticationLevel(),
                        OrgId = User.GetOrg(),
                    }
                };

                await _instanceRepository.Update(instance);

                await _instanceEventRepository.InsertInstanceEvent(instanceEvent);

                return(Ok(true));
            }

            return(Ok(true));
        }
Пример #4
0
        private async Task DispatchEvent(string eventType, Instance instance)
        {
            InstanceEvent instanceEvent = new InstanceEvent
            {
                AuthenticationLevel = 0, // update when authentication is turned on
                EventType           = eventType,
                InstanceId          = instance.Id,
                InstanceOwnerId     = instance.InstanceOwnerId,
                UserId      = 0, // update when authentication is turned on
                ProcessInfo = instance.Process,
            };

            await _instanceEventRepository.InsertInstanceEvent(instanceEvent);
        }
        public async Task <ActionResult> Post([FromBody] InstanceEvent instanceEvent)
        {
            if (instanceEvent == null || instanceEvent.InstanceId == null)
            {
                return(BadRequest("Missing parameter values: instance event must exist and instanceId must be set"));
            }

            instanceEvent.Created = DateTime.UtcNow;

            InstanceEvent result = await _repository.InsertInstanceEvent(instanceEvent);

            if (result == null)
            {
                return(BadRequest("Unable to write new instance event to database"));
            }

            return(Created(result.Id.ToString(), result));
        }
Пример #6
0
        public async Task <ActionResult <string> > Post(int instanceOwnerPartyId, Guid instanceGuid, [FromBody] InstanceEvent instanceEvent)
        {
            if (instanceEvent?.InstanceId == null)
            {
                return(BadRequest("Missing parameter values: instance event must exist and instanceId must be set"));
            }

            instanceEvent.Created = instanceEvent.Created?.ToUniversalTime() ?? DateTime.UtcNow;

            InstanceEvent result = await _repository.InsertInstanceEvent(instanceEvent);

            if (result == null)
            {
                return(BadRequest("Unable to write new instance event to database"));
            }

            return(Created(result.Id.ToString(), result));
        }
Пример #7
0
        private async Task DispatchEvent(string eventType, Instance instance)
        {
            InstanceEvent instanceEvent = new InstanceEvent
            {
                EventType            = eventType,
                InstanceId           = instance.Id,
                InstanceOwnerPartyId = instance.InstanceOwner.PartyId,
                User = new PlatformUser
                {
                    UserId = 0,              // update when authentication is turned on
                    AuthenticationLevel = 0, // update when authentication is turned on
                },

                ProcessInfo = instance.Process,
                Created     = DateTime.UtcNow,
            };

            await _instanceEventRepository.InsertInstanceEvent(instanceEvent);
        }
Пример #8
0
        private async Task DispatchEvent(string eventType, Instance instance, DataElement dataElement)
        {
            InstanceEvent instanceEvent = new InstanceEvent
            {
                EventType            = eventType,
                InstanceId           = instance.Id,
                DataId               = dataElement.Id,
                InstanceOwnerPartyId = instance.InstanceOwner.PartyId,
                User = new PlatformUser
                {
                    UserId = User.GetUserIdAsInt(),
                    AuthenticationLevel = User.GetAuthenticationLevel(),
                    OrgId = User.GetOrg(),
                },
                ProcessInfo = instance.Process,
                Created     = DateTime.UtcNow,
            };

            await _instanceEventRepository.InsertInstanceEvent(instanceEvent);
        }