コード例 #1
0
        public ActionResult Create([Bind(Include = "Id,Name,Display")] AomMeta aomMeta)
        {
            if (ModelState.IsValid)
            {
                aomMeta.Id = Guid.NewGuid();
                db.AomMetas.Add(aomMeta);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(aomMeta));
        }
コード例 #2
0
        public ActionResult Create([Bind(Include = "Id,Name")] FieldType fieldType)
        {
            if (ModelState.IsValid)
            {
                fieldType.Id = Guid.NewGuid();
                db.FieldTypes.Add(fieldType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(fieldType));
        }
コード例 #3
0
        public ActionResult Create(AomObject aomObject)
        {
            aomObject.Id = Guid.NewGuid();
            if (ModelState.IsValid)
            {
                db.AomObjects.Add(aomObject);

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(aomObject));
        }
コード例 #4
0
        public ActionResult Create([Bind(Include = "Id,AomMetaId,Name,FieldTypeId,Display")] AomFieldMeta aomFieldMeta)
        {
            if (ModelState.IsValid)
            {
                aomFieldMeta.Id = Guid.NewGuid();
                db.AomFieldMetas.Add(aomFieldMeta);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AomMetaId   = new SelectList(db.AomMetas, "Id", "Name", aomFieldMeta.AomMetaId);
            ViewBag.FieldTypeId = new SelectList(db.FieldTypes, "Id", "Name", aomFieldMeta.FieldTypeId);
            return(View(aomFieldMeta));
        }
コード例 #5
0
        public ActionResult Create([Bind(Include = "Id,PkAomMetaId,FkAomMetaId,FkAomFieldMetaId,Name,PkAomFieldMetaId")] RelationshipMeta relationshipMeta)
        {
            if (ModelState.IsValid)
            {
                relationshipMeta.Id = Guid.NewGuid();
                db.RelationshipMetas.Add(relationshipMeta);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.FkAomFieldMetaId = new SelectList(db.AomFieldMetas, "Id", "Name", relationshipMeta.FkAomFieldMetaId);
            ViewBag.FkAomMetaId      = new SelectList(db.AomMetas, "Id", "Name", relationshipMeta.FkAomMetaId);
            ViewBag.PkAomFieldMetaId = new SelectList(db.AomFieldMetas, "Id", "Name", relationshipMeta.PkAomFieldMetaId);
            ViewBag.PkAomMetaId      = new SelectList(db.AomMetas, "Id", "Name", relationshipMeta.PkAomMetaId);
            return(View(relationshipMeta));
        }
コード例 #6
0
        public NgTable <AomMeta> CreateTables(string userName, string password, string[] tables)
        {
            var result = new NgTable <AomMeta>();
            // 1. Log in to sales force
            var loggedIn = Connector.LogIn(userName, password);

            if (!loggedIn.Data)
            {
                result.LogError("Could not log into sales force");
                return(result);
            }

            // 2. check that the tables are correct
            var  tableNames = Connector.GatTablesList();
            bool isSubset   = !tables.Except(tableNames).Any();

            if (!isSubset)
            {
                result.LogError("Tables are not a subset of salesforce tables");
                return(result);
            }

            // 2. get the table definitions

            //    var tableDefinitions = Connector.DescribeTables(tables);

            // lets gt all of them
            var listN = splitList(tableNames, 50);
            List <TableInfo> tableDefinitions = new List <TableInfo>();

            foreach (var list in listN)
            {
                tableDefinitions.AddRange(Connector.DescribeTables(list.ToArray()));
            }



            var context = new AomDbContext();

            foreach (var tableDefinition in tableDefinitions)
            {
                if (!tables.ToList().Contains(tableDefinition.name))
                {
                    continue;
                }
                // 3. create table for each table definition
                AomMeta newTable = new AomMeta
                {
                    Name    = tableDefinition.name,
                    Display = tableDefinition.label
                };

                // 4. create table field for each definition
                foreach (var field in tableDefinition.fields)
                {
                    // 5. create a type for each field type
                    var fieldType = context.FieldTypes.FirstOrDefault(c => c.Name == field.type);
                    if (fieldType == null)
                    {
                        fieldType = new FieldType
                        {
                            Name = field.type
                        };
                        context.FieldTypes.Add(fieldType);
                        context.SaveChanges();
                    }

                    AomFieldMeta newField = new AomFieldMeta
                    {
                        Name      = field.name,
                        Display   = field.label,
                        FieldType = fieldType
                                    // FieldTypeId = new Guid("F96D8BB4-C3E4-437B-A8AE-9E6BCB9CFE52")
                    };
                    newTable.AomFieldMetas.Add(newField);
                }

                result.Data.Add(newTable);
                context.AomMetas.Add(newTable);
            }
            context.SaveChanges();
            result.Success = true;


            // 5 create ralationships
            foreach (var tableDefinition in tableDefinitions)
            {
                // primary key table - which is this table
                var primaryTable = context.AomMetas.SingleOrDefault(c => c.Name == tableDefinition.name);

                if (primaryTable == null)
                {
                    continue;
                }

                // primary key table field - which is this tables Id
                var primaryTableField =
                    context.AomFieldMetas.SingleOrDefault(c => c.Name == "Id" && c.AomMetaId == primaryTable.Id);
                if (primaryTableField == null)
                {
                    continue;
                }


                if (tableDefinition.relationships == null)
                {
                    continue;
                }

                foreach (var relationship in tableDefinition.relationships)
                {
                    // forigen key table - the ccurrent child table
                    var forigenTable = context.AomMetas.SingleOrDefault(c => c.Name == relationship.ChildTable);
                    if (forigenTable == null)
                    {
                        continue;
                    }

                    // forigen key table field
                    var forigenTableField =
                        context.AomFieldMetas.SingleOrDefault(c => c.Name == relationship.ChildField && c.AomMetaId == forigenTable.Id);
                    if (forigenTableField == null)
                    {
                        continue;
                    }


                    // yeah baby we have a valid relationship SWEET AS
                    context.RelationshipMetas.Add(new RelationshipMeta
                    {
                        PkAomMetaId      = primaryTable.Id,
                        FkAomMetaId      = forigenTable.Id,
                        FkAomFieldMetaId = forigenTableField.Id,
                        PkAomFieldMetaId = primaryTableField.Id
                    });
                    context.SaveChanges();
                }
            }

            return(result);
        }