public List <ClubCloud_Vereniging> GetVerenigingenForRechtsvormById(System.Guid Id, bool refresh = false, ClubCloud_Setting settings = null)
        {
            if (settings != null)
            {
                ValidateSettings(ref settings);
            }

            ClubCloud_Rechtsvorm        entity = null;
            List <ClubCloud_Vereniging> result = null;

            using (new SPMonitoredScope("Rechtsvormen GetVerenigingenForRechtsvormById"))
            {
                try
                {
                    entity = beheerModel.ClubCloud_Rechtsvormen.Find(Id);
                    if (entity != null && entity.ClubCloud_Vereniging != null && entity.ClubCloud_Vereniging.Count == 0)
                    {
                        beheerModel.Entry(entity).Collection(e => e.ClubCloud_Vereniging).Load();
                    }

                    if (entity != null)
                    {
                        result = entity.ClubCloud_Vereniging.ToList();
                    }

                    if (result == null || result.Count == 0 || refresh)
                    {
                        result = GetVerenigingenForRechtsvormById(settings.Id.ToString(), Id, refresh, settings);
                    }

                    if (result != null)
                    {
                        return(result);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteLog(Logger.Category.Unexpected, ex.Source, ex.Message);
                }
                finally
                {
                    if (entity != null)
                    {
                        try { beheerModel.ObjectContext.Detach(entity); } catch {}
                    }
                    if (result != null)
                    {
                        foreach (object item in result)
                        {
                            if (item != null)
                            {
                                try { beheerModel.ObjectContext.Detach(item); } catch {}
                            }
                        }
                    }
                }
            }

            return(new List <ClubCloud_Vereniging>());
        }
        public bool DeleteRechtsvorm(ClubCloud_Rechtsvorm entity, ClubCloud_Setting settings = null)
        {
            if (settings != null)
            {
                ValidateSettings(ref settings);
            }

            return(DeleteRechtsvormById(entity.Id, settings));
        }
        public bool SetVerenigingenForRechtsvorm(List <ClubCloud_Vereniging> Verenigingen, ClubCloud_Rechtsvorm entity, bool refresh = false, ClubCloud_Setting settings = null)
        {
            if (settings != null)
            {
                ValidateSettings(ref settings);
            }

            bool succes = false;
            ClubCloud_Rechtsvorm result = null;

            using (new SPMonitoredScope("Rechtsvormen SetVerenigingenForRechtsvorm"))
            {
                try
                {
                    entity = beheerModel.ClubCloud_Rechtsvormen.Find(entity.Id);

                    if (entity != null)
                    {
                        beheerModel.Entry(entity).Collection(e => e.ClubCloud_Vereniging).Load();
                    }
                    //result = GetRechtsvormById(settings.Id.ToString(), Id, refresh, settings);

                    if (result != null)
                    {
                        //return result.ClubCloud_Rechtsvormen.Count == ;

                        succes = false;
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteLog(Logger.Category.Unexpected, ex.Source, ex.Message);
                }
                finally
                {
                    if (entity != null)
                    {
                        try { beheerModel.ObjectContext.Detach(entity); } catch {}
                    }
                }
            }

            return(succes);
        }
        public ClubCloud_Rechtsvorm GetRechtsvormById(System.Guid Id, bool refresh = false, ClubCloud_Setting settings = null)
        {
            if (settings != null)
            {
                ValidateSettings(ref settings);
            }

            ClubCloud_Rechtsvorm result = null;

            using (new SPMonitoredScope("Rechtsvormen GetRechtsvormById"))
            {
                try
                {
                    result = beheerModel.ClubCloud_Rechtsvormen.Find(Id);

                    if (result == null || refresh)
                    {
                        result = GetRechtsvormById(settings.Id.ToString(), Id, refresh, settings);
                    }

                    if (result != null)
                    {
                        return(result);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteLog(Logger.Category.Unexpected, ex.Source, ex.Message);
                }
                finally
                {
                    if (result != null)
                    {
                        try { beheerModel.ObjectContext.Detach(result); } catch {}
                    }
                }
            }

            return(new ClubCloud_Rechtsvorm());
        }
        public ClubCloud_Rechtsvorm SetRechtsvorm(ClubCloud_Rechtsvorm entity, ClubCloud_Setting settings = null)
        {
            if (settings != null)
            {
                ValidateSettings(ref settings);
            }

            ClubCloud_Rechtsvorm tobeupdated = null;

            using (new SPMonitoredScope("Rechtsvormen SetRechtsvorm"))
            {
                try
                {
                    entity = SetRechtsvorm(settings.Id.ToString(), entity, settings);

                    if (entity != null)
                    {
                        beheerModel.ClubCloud_Rechtsvormen.AddOrUpdate(entity);
                    }

                    beheerModel.SaveChanges();

                    tobeupdated = beheerModel.ClubCloud_Rechtsvormen.Find(entity.Id);
                    return(tobeupdated);
                }
                catch (Exception ex)
                {
                    Logger.WriteLog(Logger.Category.Unexpected, ex.Source, ex.Message);
                }
                finally
                {
                    if (tobeupdated != null)
                    {
                        try { beheerModel.ObjectContext.Detach(tobeupdated); } catch {}
                    }
                }
            }

            return(null);
        }
        public bool DeleteRechtsvormById(System.Guid Id, ClubCloud_Setting settings = null)
        {
            if (settings != null)
            {
                ValidateSettings(ref settings);
            }

            bool succes = false;
            ClubCloud_Rechtsvorm tobedeleted = null;

            using (new SPMonitoredScope("Rechtsvormen DeleteRechtsvormById"))
            {
                try
                {
                    tobedeleted = beheerModel.ClubCloud_Rechtsvormen.Find(Id);

                    if (tobedeleted != null)
                    {
                        beheerModel.ClubCloud_Rechtsvormen.Remove(tobedeleted);
                        beheerModel.SaveChanges();
                    }
                    succes = true;
                }
                catch (Exception ex)
                {
                    Logger.WriteLog(Logger.Category.Unexpected, ex.Source, ex.Message);
                }
                finally
                {
                    if (tobedeleted != null)
                    {
                        try { beheerModel.ObjectContext.Detach(tobedeleted); } catch {}
                    }
                }
            }

            return(succes);
        }