예제 #1
0
        private bool UpdateElements(EntityBundle item)
        {
            if (item.elementsDirty)
            {
                if (this.DeleteElements(item.Id))
                {
                    try
                    {
                        NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString);
                        cmd.CommandText = Db.InsertElement;

                        foreach (BundleElement cur in item.Elements)
                        {
                            cmd.Parameters.Clear();
                            cmd.Parameters.AddWithValue("id", cur.BundleId);
                            cmd.Parameters.AddWithValue("esid", cur.EntityId.DataStoreIdentity);
                            cmd.Parameters.AddWithValue("eid", cur.EntityId.Identity);
                            cmd.Parameters.AddWithValue("name", cur.LocalKey);
                            cmd.Parameters.AddWithValue("val", cur.DisplayName);

                            Db.ExecuteNonQuery(cmd);
                        }

                        item.elementsDirty = false;
                        return(true);
                    }
                    catch
                    { }
                }
            }
            return(false);
        }
예제 #2
0
        public EntityBundle Get(Guid id)
        {
            if (!Guid.Empty.Equals(id) && this.CanGet())
            {
                NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString);
                cmd.CommandText = Db.SelectBundle + Db.SelectById;
                cmd.Parameters.AddWithValue("id", id);
                NpgsqlDataReader rdr = Db.ExecuteReader(cmd);
                EntityBundle     o   = null;
                if (rdr != null)
                {
                    try
                    {
                        if (rdr.Read())
                        {
                            o = EntityBundleBuilder.Instance.Build(rdr);
                        }

                        if (cmd.Connection.State == System.Data.ConnectionState.Open)
                        {
                            cmd.Connection.Close();
                        }
                    }
                    catch
                    { }
                    finally
                    {
                        cmd.Dispose();
                    }
                }
                return(o);
            }
            return(null);
        }
예제 #3
0
 public bool CanDelete(EntityBundle bundle)
 {
     if (bundle != null && this.CanDelete())
     {
         return(true); //TODO -- implement this
     }
     return(false);
 }
예제 #4
0
 public bool Delete(EntityBundle item)
 {
     if (item != null && this.CanDelete(item))
     {
         return(this.Delete(item.Id));
     }
     return(false);
 }
예제 #5
0
        public bool Update(EntityBundle item)
        {
            if (item != null && this.CanUpdate(item))
            {
                try
                {
                    NpgsqlCommand cmd = Db.GetCmd(Db.ConnectionString);
                    cmd.CommandText = Db.UpdateBundle;
                    cmd.Parameters.AddWithValue("id", item.Id);
                    cmd.Parameters.AddWithValue("name", item.Name);
                    cmd.Parameters.AddWithValue("osid", item.PrincipalOrgId.DataStoreIdentity);
                    cmd.Parameters.AddWithValue("oid", item.PrincipalOrgId.Identity);

                    Db.ExecuteNonQuery(cmd);

                    return(this.UpdateElements(item));
                }
                catch
                { }
            }
            return(false);
        }