Пример #1
0
        /// <summary>
        /// 编辑图文消息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public DocPic EditDocPic(DocPicEditReqeust info)
        {
            ValiDatas.valiData(info);
            ValiCode(info.Code, info.Id);
            using (var db = new DefaultContainer()) {
                var row = db.Db_BaseDocSet.OfType <Db_DocPic>().Single(p => p.Id == this.Id);
                row.Caption  = info.Caption;
                row.Code     = info.Code;
                row.Content  = info.Content;
                row.Descript = info.Descript;

                //删除原来的分类
                db.Database.ExecuteSqlCommand("delete from Db_BaseDocTreeSet where Db_BaseDocId=@docId", new SqlParameter("@docId", this.Id));
                //新增分类
                if (info.TreeIds != null)
                {
                    if (info.TreeIds.Count > 0)
                    {
                        List <Db_BaseDocTree> dbTrees = new List <Db_BaseDocTree>();
                        foreach (var item in info.TreeIds)
                        {
                            dbTrees.Add(new Db_BaseDocTree()
                            {
                                Id           = Guid.NewGuid().ToString(),
                                Db_BaseDocId = this.Id,
                                TreeId       = item
                            });
                        }
                        db.Db_BaseDocTreeSet.AddRange(dbTrees);
                    }
                }
                db.SaveChanges();
                return(new DocPic(row));
            }
        }
Пример #2
0
        /// <summary>
        /// 新增图文集
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static DocPic CreateDocPic(DocPicEditReqeust info)
        {
            ValiDatas.valiData(info);
            ValiCode(info.Code);
            using (var db = new DefaultContainer()) {
                var       newId  = Guid.NewGuid().ToString();
                Db_DocPic newRow = new Db_DocPic()
                {
                    Caption   = info.Caption,
                    Code      = info.Code,
                    Content   = info.Content,
                    CreatedOn = DateTime.Now,
                    Descript  = info.Descript,
                    DocType   = BaseDocType.图文集.GetHashCode(),
                    Id        = newId
                };
                //所在分类信息

                if (info.TreeIds != null)
                {
                    if (info.TreeIds.Count > 0)
                    {
                        List <Db_BaseDocTree> dbTrees = new List <Db_BaseDocTree>();
                        foreach (var item in info.TreeIds)
                        {
                            dbTrees.Add(new Db_BaseDocTree()
                            {
                                Id           = Guid.NewGuid().ToString(),
                                Db_BaseDocId = newId,
                                TreeId       = item
                            });
                        }
                        db.Db_BaseDocTreeSet.AddRange(dbTrees);
                    }
                }

                db.Db_BaseDocSet.Add(newRow);
                db.SaveChanges();
                return(new DocPic(newRow));
            }
        }