public Task DeleteEntityAsync(IEntityWithID entity)
        {
            Task t = Task <int> .Run(() =>
            {
                DeleteEntity(entity);
            });

            return(t);
        }
        private void DeleteEntity(IEntityWithID entity)
        {
            using (var ctx = new HappyDogShowContext())
            {
                HandlerEntry foundEntity = ctx.HandlerEntries.Where(d => d.ID == entity.Id).First();

                if (foundEntity != null)
                {
                    ctx.HandlerEntries.Remove(foundEntity);
                    ctx.SaveChanges();
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create.
        /// </summary>
        /// <param name="statePath">The state path whose execution is denied.</param>
        /// <param name="statefulObject">The stateful object against which the state path execution was denied.</param>
        /// <param name="message">The message of the exception.</param>
        public StatePathAccessDeniedException(StatePath statePath, IEntityWithID <long> statefulObject, string message)
            : base(message)
        {
            if (statePath == null)
            {
                throw new ArgumentNullException(nameof(statePath));
            }
            if (statefulObject == null)
            {
                throw new ArgumentNullException(nameof(statefulObject));
            }

            this.StatePathCodeName = statePath.CodeName;
            this.StatefulObjectID  = statefulObject.ID;
        }
        private void DeleteEntity(IEntityWithID entity)
        {
            using (var ctx = new HappyDogShowContext())
            {
                BreedEntry foundEntity = ctx.BreedEntries.Where(d => d.ID == entity.Id).Include(b => b.EnteredClasses).First();

                if (foundEntity != null)
                {
                    if (foundEntity.EnteredClasses != null)
                    {
                        foundEntity.EnteredClasses.Clear();
                    }
                    ctx.BreedEntries.Remove(foundEntity);
                    ctx.SaveChanges();
                }
            }
        }
Exemplo n.º 5
0
        private async void ExecuteCommand(T vm)
        {
            vm.CurrentEntity.ValidateProperties();

            if (vm.CurrentEntity.HasErrors)
            {
                return;
            }

            try
            {
                vm.MarkAsBusy();

                try
                {
                    await PerformSave(vm.CurrentEntity);
                }
                catch
                {
                    throw new CouldNotSaveExistingEntityException(vm.CurrentEntity);
                }
                finally
                {
                    vm.MarkAsNotBusy();
                }

                IEntityWithID entityWithID = vm.CurrentEntity as IEntityWithID;
                if (entityWithID != null)
                {
                    _eventAggregator.GetEvent <EntityUpdatedEvent <U> >().Publish(new EntityUpdatedEventArgument(entityWithID.Id));
                }

                await HandleSuccessfulSave(vm);
            }
            catch (Exception ex)
            {
                vm.MarkAsNotBusy();
                HandleUnsuccessfulSave(ex);
            }
        }
        private async void ExecuteCommand(T vm)
        {
            vm.CurrentEntity.ValidateProperties();

            if (vm.CurrentEntity.HasErrors)
            {
                return;
            }

            try
            {
                vm.MarkAsBusy();

                int result = await PerformSaveAndGetIDBack(vm.CurrentEntity);

                vm.MarkAsNotBusy();

                if (result == -1)
                {
                    throw new CouldNotSaveNewEntityException(vm.CurrentEntity);
                }
                else
                {
                    IEntityWithID entityWithID = vm.CurrentEntity as IEntityWithID;
                    if (entityWithID != null)
                    {
                        entityWithID.Id = result;
                    }
                }

                _eventAggregator.GetEvent <NewEntityCreatedEvent <U> >().Publish(new NewEntityCreatedEventArgument(result));

                HandleSuccessfulSave(vm, result);
            }
            catch (Exception ex)
            {
                vm.MarkAsNotBusy();
                HandleUnsuccessfulSave(ex);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Create.
 /// </summary>
 /// <param name="statePath">The state path whose execution is denied.</param>
 /// <param name="statefulObject">The stateful object against which the state path execution was denied.</param>
 public StatePathAccessDeniedException(StatePath statePath, IEntityWithID <long> statefulObject)
     : this(statePath, statefulObject, $"Access to state path '{statePath.Name}' is denied.")
 {
 }
Exemplo n.º 8
0
 public CouldNotDeleteExistingEntityException(IEntityWithID entity)
     : base("Could not delete existing entity")
 {
     Entity = entity;
 }