Ejemplo n.º 1
0
 public IHttpActionResult SettingsSave(dynamic data)
 {
     try
     {
         foreach (var file in data.files)
         {
             foreach (var item in data.list)
             {
                 if (item.DictKey.ToString() == file.propertyName.ToString())
                 {
                     item.DictValue = UpFileClass.FileSave(file.filePath.ToString(), item.DictValue.ToString(), (int)file.fileType);
                 }
             }
         }
         Dbctx.GgcmsDictionaries
         .ToList()
         .ForEach(x =>
         {
             foreach (var item in data.list)
             {
                 if (x.Id == (int)item.Id)
                 {
                     x.DictValue = item.DictValue.ToString();
                 }
             }
         });
         Dbctx.SaveChanges();
         CacheHelper.RemoveAllCache(CacheTypeNames.SysConfigs.ToString());
         return(Ok(data.list));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Ejemplo n.º 2
0
        // POST: api/GgcmsCategories
        public IHttpActionResult Add(GgcmsAdverts info)
        {
            UpFileClass.FileSave(info, info.files.FindAll(x => x.fileType != 3));
            var result = Dbctx.GgcmsAdverts.Add(info);

            Dbctx.SaveChanges();
            ClearCache();
            return(Ok(result));
        }
Ejemplo n.º 3
0
        // POST: api/GgcmsCategories
        public IHttpActionResult Add(GgcmsArticles info)
        {
            //提交除附加模型外的文件-标题图,内容中的图
            UpFileClass.FileSave(info, info.files.FindAll(x => x.fileType != 3));
            info.CreateTime = DateTime.Now;
            updateArticleNumber(info.Category_Id, 1);
            CacheHelper.RemoveAllCache(CacheTypeNames.Categorys);
            if (info.ModuleInfo != null && info.ModuleInfo.Id > 0)
            {
                info.ExtModelId = info.ModuleInfo.Id;
            }
            info.pagesCount = info.pages.Count + 1;
            var result = Dbctx.GgcmsArticles.Add(info);

            Dbctx.SaveChanges();
            //附件
            using (GgcmsDB db = new GgcmsDB())
            {
                foreach (GgcmsAttachments attach in info.attachments)
                {
                    attach.Articles_Id = info.Id;
                    attach.CreateTime  = DateTime.Now;
                    db.GgcmsAttachments.Add(attach);
                }
                db.SaveChanges();
            }
            //数据模型
            if (info.ModuleInfo != null && info.ModuleInfo.Id > 0)
            {
                foreach (var file in info.files.FindAll(x => x.fileType == 3))
                {
                    foreach (var item in info.ModuleInfo.Columns)
                    {
                        if (item.ColName == file.propertyName)
                        {
                            item.Value = UpFileClass.FileSave(file.filePath.ToString(), item.Value.ToString(), (int)file.fileType);
                        }
                    }
                }
                ExtendModule.SaveData(info.Id, info.ModuleInfo);
            }

            //分页保存
            if (info.pages.Count > 0)
            {
                foreach (var page in info.pages)
                {
                    UpFileClass.FileSave(page, page.files);
                    page.Article_Id = info.Id;
                    Dbctx.GgcmsArticlePages.Add(page);
                }
                Dbctx.SaveChanges();
            }
            ClearCache();
            return(Ok(result));
        }
Ejemplo n.º 4
0
        // POST: api/GgcmsCategories
        public IHttpActionResult Add(GgcmsFriendLinks info)
        {
            var result = Dbctx.GgcmsFriendLinks.Add(info);

            UpFileClass.FileSave(info, info.files);
            Dbctx.SaveChanges();
            ClearCache();
            CacheHelper.RemoveAllCache(CacheTypeNames.Keys);
            return(Ok(result));
        }
Ejemplo n.º 5
0
        // PUT: api/GgcmsCategories/5
        public IHttpActionResult Edit(GgcmsFriendLinks info)
        {
            if (Dbctx.GgcmsFriendLinks.Where(x => x.Id == info.Id).Count() == 0)
            {
                return(BadRequest("信息不存在"));
            }
            UpFileClass.FileSave(info, info.files);
            //Dbctx.GgcmsFriendLinks.Attach(info);
            //Dbctx.Entry(info).Property("goods_name").IsModified = true;
            var ent = Dbctx.Entry(info);

            ent.State = EntityState.Modified;
            Dbctx.SaveChanges();
            ClearCache();
            CacheHelper.RemoveAllCache(CacheTypeNames.Keys);
            return(Ok(info));
        }
Ejemplo n.º 6
0
        // PUT: api/GgcmsCategories/5
        public IHttpActionResult Edit(GgcmsCategories info)
        {
            if (Dbctx.GgcmsCategories.Where(x => x.Id == info.Id).Count() == 0)
            {
                return(BadRequest("信息不存在"));
            }
            info.RouteKey = HttpUtility.UrlEncode(info.RouteKey);
            UpFileClass.FileSave(info, info.files);

            //Dbctx.GgcmsCategories.Attach(info);
            //Dbctx.Entry(info).Property("goods_name").IsModified = true;
            var ent = Dbctx.Entry(info);

            ent.State = EntityState.Modified;
            Dbctx.SaveChanges();
            ClearCache();
            return(Ok(info));
        }
Ejemplo n.º 7
0
        // PUT: api/GgcmsCategories/5
        public IHttpActionResult Edit(GgcmsArticles info)
        {
            if (Dbctx.GgcmsArticles.Where(x => x.Id == info.Id).Count() == 0)
            {
                return(BadRequest("信息不存在"));
            }
            //Dbctx.GgcmsArticles.Attach(info);
            //Dbctx.Entry(info).Property("goods_name").IsModified = true;
            var ent = Dbctx.Entry(info);

            ent.State       = EntityState.Modified;
            info.pagesCount = info.pages.Where(x => x.state != EntityState.Deleted).Count() + 1;
            UpFileClass.FileSave(info, info.files.FindAll(x => x.fileType != 3));
            var old = Dbctx.GgcmsArticles.Find(info.Id);

            if (old.Category_Id != info.Category_Id)
            {
                updateArticleNumber(info.Category_Id, 1);
                updateArticleNumber(old.Category_Id, -1);
                CacheHelper.RemoveAllCache(CacheTypeNames.Categorys);
            }
            var list = Dbctx.GgcmsAttachments.Where(x => x.Articles_Id == info.Id).ToList();

            //附件
            foreach (GgcmsAttachments attach in list)
            {
                var item = info.attachments.Find(x => x.Id == attach.Id);
                if (item == null)
                {
                    Dbctx.GgcmsAttachments.Remove(attach);
                }
                else
                {
                    attach.AttaUrl    = item.AttaUrl;
                    attach.AttaTitle  = item.AttaTitle;
                    attach.Describe   = item.Describe;
                    attach.CreateTime = DateTime.Now;
                    attach.RealName   = item.RealName;
                }
            }
            foreach (GgcmsAttachments attach in info.attachments)
            {
                if (attach.Id == 0)
                {
                    attach.Articles_Id = info.Id;
                    attach.CreateTime  = DateTime.Now;
                    Dbctx.GgcmsAttachments.Add(attach);
                }
            }
            if (info.ModuleInfo != null)
            {
                info.ExtModelId = info.ModuleInfo.Id;
                if (old.ExtModelId > 0 && info.ExtModelId != old.ExtModelId)
                {
                    ExtendModule.Delete(info.Id, old.ExtModelId);
                }
                foreach (var file in info.files.FindAll(x => x.fileType == 3))
                {
                    foreach (var item in info.ModuleInfo.Columns)
                    {
                        if (item.ColName == file.propertyName)
                        {
                            item.Value = UpFileClass.FileSave(file.filePath.ToString(), item.Value.ToString(), (int)file.fileType);
                        }
                    }
                }
                ExtendModule.SaveData(info.Id, info.ModuleInfo);
            }
            else if (old.ExtModelId > 0)
            {
                ExtendModule.Delete(info.Id, old.ExtModelId);
            }
            //分页保存
            if (info.pages.Count > 0)
            {
                foreach (var page in info.pages)
                {
                    UpFileClass.FileSave(page, page.files);
                    if (page.state == EntityState.Added)
                    {
                        page.Article_Id = info.Id;
                        Dbctx.GgcmsArticlePages.Add(page);
                    }
                    else if (page.state == EntityState.Modified)
                    {
                        var pageEnt = Dbctx.Entry(page);
                        pageEnt.State = EntityState.Modified;
                    }
                    else if (page.state == EntityState.Deleted)
                    {
                        var p = Dbctx.GgcmsArticlePages.Find(page.Id);
                        if (p != null)
                        {
                            Dbctx.GgcmsArticlePages.Remove(p);
                        }
                    }
                    //只更新分页信息
                    else if (page.state == EntityState.Unchanged)
                    {
                        Dbctx.GgcmsArticlePages.Attach(page);
                        Dbctx.Entry(info).Property("OrderId").IsModified = true;
                    }
                }
            }
            Dbctx.SaveChanges();
            ClearCache();
            return(Ok(info));
        }