Beispiel #1
0
        public Tuple <bool, GeologyMappingType> Update(GeologyMappingTypeDto dto)
        {
            var model = GetGeologyMappingType(dto.Id);

            if (model == null)
            {
                return(new Tuple <bool, GeologyMappingType>(false, null));
            }

            model.ParentID = dto.ParentID;

            //获取父级
            var parent = GetGeologyMappingType(dto.ParentID);

            if (parent == null)
            {
                return(new Tuple <bool, GeologyMappingType>(false, null));
            }

            model.Paths     = parent.Paths + "." + dto.Id;
            model.ClassName = dto.ClassName;

            var entity = model.MapTo <GeologyMappingType>();
            var db     = _GeologyMappingType.GetDbContext();
            var sql    = _GeologyMappingType.GenerateUpdateSql(entity);
            var flag   = db.Database.ExecuteSqlCommand(sql) > 0;


            return(new Tuple <bool, GeologyMappingType>(flag, entity));
        }
Beispiel #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));
            }
        }