Пример #1
0
        public virtual ActionResult Delete(Element[] model, ElementCategory[] categoryList)
        {
            JsonResultEntry entry = new JsonResultEntry();

            try
            {
                var category = ControllerContext.RequestContext.GetRequestValue("Category");

                if (model != null)
                {
                    foreach (var m in model)
                    {
                        m.Category = category;
                        Remove(m);
                    }
                }

                if (categoryList != null)
                {
                    foreach (var c in categoryList)
                    {
                        Manager.RemoveCategory(Site, c.Category);
                    }
                }
            }
            catch (Exception e)
            {
                entry.AddException(e);
            }

            return Json(entry);
        }
Пример #2
0
 public virtual void Add(Site site, Element element)
 {
     var oldElement = Get(site, element.Category, element.Name, element.Culture);
     if (oldElement != null)
     {
         throw new ItemAlreadyExistsException();
     }
     SiteLabel.GetElementRepository(site).Add(element);
 }
Пример #3
0
        public virtual ActionResult Create(Element model, FormCollection forms)
        {
            try
            {
                Add(model);
                //return RedirectToIndex();
            }
            catch (FriendlyException e)
            {
                ModelState.AddModelError("", e.Message);

            }
            return View(model);
        }
Пример #4
0
        public static Element Map(this string source, string key, string category, CultureInfo culture)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                return Element.Empty;
            }

            var repository = ElementRepository.DefaultRepository;

            var element = repository.Get(key, category, culture.Name);
            if (element == null)
            {
                element = new Element() { Name = source, Category = category, Culture = culture.Name, Value = source };

                repository.Add(element);
            }
            return element;
        }
Пример #5
0
 protected virtual void Remove(Element model)
 {
     Manager.Remove(Site, model);
 }
Пример #6
0
 protected virtual void Add(Element model)
 {
     Manager.Add(Site, model);
 }
Пример #7
0
 public virtual ActionResult Translate(Element model)
 {
     return Create(model);
 }
Пример #8
0
        public virtual ActionResult Delete(string[] docs, string[] folders)
        {
            var data = new JsonResultData(ModelState);
            data.RunWithTry((resultData) =>
            {
                var category = ControllerContext.RequestContext.GetRequestValue("Category");

                if (docs != null)
                {
                    foreach (var name in docs)
                    {
                        var m = new Element() { Name = name };
                        m.Category = category;
                        Remove(m);
                    }
                }

                if (folders != null)
                {
                    foreach (var c in folders)
                    {
                        Manager.RemoveCategory(Site, c);
                    }
                }

                resultData.ReloadPage = true;
            });
            return Json(data);
        }
Пример #9
0
 public virtual ActionResult UpdateLable(string key, string category, string value)
 {
     var result = new JsonResultEntry();
     try
     {
         var element = new Element() { Name = key, Category = category, Value = value };
         CMS.Sites.Services.ServiceFactory.LabelManager.Update(Site.Current, element);
     }
     catch (Exception e)
     {
         result.AddException(e);
     }
     return Json(result);
 }
Пример #10
0
 public virtual ActionResult UpdateLable(string key, string category, string value)
 {
     var data = new JsonResultData(ModelState);
     data.RunWithTry((resultData) =>
         {
             var element = new Element() { Name = key, Category = category, Value = value };
             ServiceFactory.LabelManager.Update(Site.Current, element);
         });
     return Json(data);
 }
Пример #11
0
        public virtual void Update(Site site, Element element)
        {
            element.Culture = null;
            SiteLabel.GetElementRepository(site).Update(element);

            SiteLabel.ClearCache(site);
        }
Пример #12
0
 public bool Remove(Element element)
 {
     var key = GetElementKey(element.Name, element.Category, element.Culture);
     DataHelper.DeleteItemByKey(Site, ModelExtensions.GetBucketDocumentKey(ModelExtensions.LabelCategoryDataType, key));
     return true;
 }
Пример #13
0
 private void InsertOrUpdateLabel(Element @new, Element old)
 {
     if (!string.IsNullOrEmpty(@new.Category))
     {
         AddCategory(@new.Category, @new.Culture);
     }
     var key = GetElementKey(@new.Name, @new.Category, @new.Culture);
     DataHelper.StoreObject(Site, @new, key, ModelExtensions.LabelDataType);
 }
Пример #14
0
 public bool Update(Element element)
 {
     element.Culture = FileCulture;
     return this.StoreRepository.Update(element);
 }
Пример #15
0
 public bool Remove(Element element)
 {
     element.Culture = FileCulture;
     return this.StoreRepository.Remove(element);
 }
Пример #16
0
 public bool Add(Element element)
 {
     element.Culture = FileCulture;
     return this.StoreRepository.Add(element);
 }
Пример #17
0
        private static string LabelValue(string defaultValue, string key, string category, Site site)
        {
            if (string.IsNullOrEmpty(key) && string.IsNullOrEmpty(category))
            {
                return defaultValue;
            }
            var repository = GetElementRepository(site);

            var element = repository.Get(key, category, "en-US");

            string value = "";
            if (element == null)
            {
                element = new Element() { Name = key, Category = category ?? "", Culture = "en-US", Value = defaultValue };

                repository.Add(element);

                value = element.Value;
            }
            else
            {
                value = element.Value;
            }
            return value;
        }
Пример #18
0
 protected virtual void Update(Element model)
 {
     Manager.Update(Site, model);
 }
Пример #19
0
 public virtual ActionResult Create(Element model)
 {
     ModelState.Clear();
     return View(model);
 }
Пример #20
0
 public bool Remove(Element element)
 {
     var entity = _dbContext.Labels
            .Where(it => it.SiteName == SiteName && it.Name == element.Name && it.Category == (element.Category ?? ""))
            .FirstOrDefault();
     if (entity != null)
     {
         _dbContext.Labels.Remove(entity);
         _dbContext.SaveChanges();
     }
     return true;
 }
Пример #21
0
 public bool Remove(Element element)
 {
     var entity = new LabelEntity(SiteName, element);
     var serviceContext = CloudTableHelper.GetTableServiceContext();
     entity = serviceContext.CreateQuery<LabelEntity>(LabelTable)
            .Where(it => it.PartitionKey == SiteName && it.RowKey == entity.RowKey)
            .FirstOrDefault();
     if (entity != null)
     {
         serviceContext.DeleteObject(entity);
         serviceContext.SaveChangesWithRetries();
     }
     return true;
 }
Пример #22
0
 public bool Add(Element element)
 {
     InsertOrUpdateLabel(element, element);
     return true;
 }
Пример #23
0
 private void InsertOrUpdateLabel(Element @new, Element old)
 {
     var entity = _dbContext.Labels
           .Where(it => it.SiteName == SiteName && it.Name == @new.Name && it.Category == (@new.Category ?? ""))
           .FirstOrDefault();
     if (entity != null)
     {
         entity.Value = @new.Value;
     }
     else
     {
         if (!string.IsNullOrEmpty(@new.Category))
         {
             AddCategory(@new.Category, @new.Culture);
         }
         entity = new LabelEntity(SiteName, @new);
         _dbContext.Labels.Add(entity);
     }
     _dbContext.SaveChanges();
 }
Пример #24
0
 private void InsertOrUpdateLabel(Element @new, Element old)
 {
     var serviceContext = CloudTableHelper.GetTableServiceContext();
     var entity = new LabelEntity(SiteName, @new);
     if (Get(old.Name, old.Category, old.Culture) == null)
     {
         if (!string.IsNullOrEmpty(@new.Category))
         {
             AddCategory(@new.Category, @new.Culture);
         }
         serviceContext.AddObject(LabelTable, entity);
     }
     else
     {
         serviceContext.AttachTo(LabelTable, entity, "*");
         serviceContext.UpdateObject(entity);
     }
     serviceContext.SaveChangesWithRetries();
 }
Пример #25
0
 public LabelEntity(string siteName, Element element)
     : this(siteName, element.Name, element.Value, element.Category)
 {
 }
Пример #26
0
 public virtual ActionResult Edit(Element model, FormCollection collection)
 {
     JsonResultEntry resultEntry = new JsonResultEntry(ModelState);
     try
     {
         //if (ModelState.IsValid)
         //{
         Update(model);
         //}
         //return RedirectToIndex();
     }
     catch (Exception e)
     {
         resultEntry.AddException(e);
     }
     return Json(resultEntry);
 }
Пример #27
0
 public ElementCacheKey(Element element)
     : this(element.Name, element.Category, element.Culture)
 {
 }
Пример #28
0
 public virtual ActionResult Edit(Element model, string @return)
 {
     var data = new JsonResultData(ModelState);
     data.RunWithTry((resultData) =>
     {
         Update(model);
         resultData.RedirectUrl = @return;
     });
     return Json(data);
 }