예제 #1
0
        public int ImportMappingType(RowData data)
        {
            var db    = _GeologyMappingType.GetDbContext();
            var count = 0;

            if (data.Rows != null && data.Rows.Any())
            {
                foreach (var row in data.Rows)
                {
                    var model = new GeologyMappingType
                    {
                        ClassName = row.ClassName,
                        Id        = row.Id,
                        Paths     = row.Paths,
                        ParentID  = row.ParentID
                    };
                    var sql = _GeologyMappingType.GenerateInsertSql(model);
                    try
                    {
                        var flag = db.Database.ExecuteSqlCommand(sql) > 0;
                        if (flag)
                        {
                            count++;
                        }
                    }
                    catch
                    {
                    }
                }
            }
            return(count);
        }
예제 #2
0
        public Tuple <bool, GeologyMappingType> Insert(GeologyMappingTypeDto dto)
        {
            var id = Guid.NewGuid().ToString();
            var db = _GeologyMappingType.GetDbContext();

            if (string.IsNullOrEmpty(dto.ParentID))
            {
                var model = new GeologyMappingType
                {
                    ClassName = dto.ClassName,
                    Id        = id,
                    Paths     = id
                };
                var sql  = _GeologyMappingType.GenerateInsertSql(model);
                var flag = db.Database.ExecuteSqlCommand(sql) > 0;
                return(new Tuple <bool, GeologyMappingType>(flag, model));
            }
            else
            {
                //获取父级
                var parent = GetGeologyMappingType(dto.ParentID);
                if (parent == null)
                {
                    return(new Tuple <bool, GeologyMappingType>(false, null));
                }

                var model = new GeologyMappingType
                {
                    ClassName = dto.ClassName,
                    Id        = id,
                    Paths     = parent.Paths + "." + id,
                    ParentID  = dto.ParentID
                };
                var sql  = _GeologyMappingType.GenerateInsertSql(model);
                var flag = db.Database.ExecuteSqlCommand(sql) > 0;
                return(new Tuple <bool, GeologyMappingType>(flag, model));
            }
        }