Example #1
0
 public void SaveText(as_texts item)
 {
     try {
         RDL.CacheManager.PurgeCacheItems("as_text_" + item.code);
         db.SaveText(item);
     }catch (Exception ex) {
         RDL.Debug.LogError(ex);
     }
 }
Example #2
0
        public int CodeIs(as_texts item)
        {
            int error = -1;

            using (var dbContextTransaction = db.db.Database.BeginTransaction())
            {
                try
                {
                    RDL.CacheManager.PurgeCacheItems("as_text_" + item.code);
                    as_texts res = db.db.as_texts.SingleOrDefault(el => el.code == item.code);
                    if (res == null)
                    {
                        db.db.as_texts.Add(item);
                        error = db.db.SaveChanges();
                        CacheManager.CacheData("as_text_" + item.code, res);
                    }
                    else
                    {
                        res.code = "Temp|ID" + res.id + "|" + res.code;
                        as_texts resTemp = db.db.as_texts.SingleOrDefault(el => el.code == res.code);
                        item.id = res.id;
                        if (string.IsNullOrEmpty(item.name))
                        {
                            item.name = res.name;
                        }
                        if (resTemp == null)
                        {
                            db.db.Entry(res).State = EntityState.Added;
                            error = db.db.SaveChanges();
                        }
                        else
                        {
                            error = 0;
                        }
                        if (error >= 0)
                        {
                            error    = -1;
                            res      = db.db.as_texts.SingleOrDefault(el => el.id == item.id);
                            res.text = item.text;
                            res.code = item.code;
                            res.name = item.name;
                            error    = db.db.SaveChanges();
                            CacheManager.CacheData("as_text_" + item.code, res);
                        }
                    }
                    dbContextTransaction.Commit();
                }
                catch (Exception ex)
                {
                    error = -1;
                    dbContextTransaction.Rollback();
                    Debug.LogError(ex);
                }
            }
            return(error);
        }
        public ActionResult ArkImgSave(string ImgText, string codeDiv, string NameDiv)
        {
            string      STATUS = "BAD";
            TextManager obj    = new TextManager();

            as_texts at = new as_texts {
                id = 0, name = NameDiv, code = codeDiv, text = ImgText, categoryID = null
            };

            if (obj.CodeIs(at) >= 0)
            {
                STATUS = "OK";
            }
            string json = "";

            json = Newtonsoft.Json.JsonConvert.SerializeObject(new
            {
                STATUS = STATUS
            });
            return(Content(json, "application/json"));
        }
        public ActionResult ArkImgExist(string codeDiv)
        {
            string      STATUS    = "BAD";
            TextManager obj       = new TextManager();
            as_texts    GetCodeIs = obj.GetCodeIs(codeDiv);

            if (GetCodeIs != null)
            {
                STATUS = "ItExists";
            }
            else
            {
                STATUS = "NotExist";
            }
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(new
            {
                STATUS = STATUS
            });

            return(Content(json, "application/json"));
        }
Example #5
0
        public as_texts GetText(string code)
        {
            var res = new as_texts();
            var key = "as_text_" + code;

            if (CacheManager.EnableCaching && CacheManager.Cache[key] != null)
            {
                res = (as_texts)CacheManager.Cache[key];
            }
            else
            {
                try
                {
                    res = GetTexts().FirstOrDefault(x => x.code == code);
                    CacheManager.CacheData(key, res);
                }
                catch (Exception ex)
                {
                    Debug.LogError(ex);
                }
            }
            return(res);
        }
        public ActionResult SaveText(string code, string text)
        {
            var mng     = new TextManager();
            var mng2    = new RightsManager();
            var canEdit = mng2.CheckRightForUser(User.Identity.Name, "canEditInlineText");

            var msg = "";
            var res = false;

            if (canEdit)
            {
                var item = mng.GetText(code);
                if (item == null)
                {
                    item = new as_texts {
                        categoryID = null, code = code, id = 0, name = code, text = text
                    };
                }
                else
                {
                    item.text = text;
                }
                mng.SaveText(item);
                res = true;
            }
            else
            {
                msg = "У вас нет прав на редактирование этого текста. Обратитесь к администрации сайта";
            }

            return(Json(new
            {
                result = res,
                msg = msg
            }));
        }
Example #7
0
        public as_texts GetCodeIs(string code)
        {
            as_texts res = db.db.as_texts.SingleOrDefault(el => el.code == code);

            return(res);
        }