示例#1
0
        public int AddQuickAdvice(QuickAdvice quickAdvice)
        {
            _store.QuickAdvices.Add(quickAdvice);

            CreateOrChangeEntityLanguage(quickAdvice);

            _store.SaveChanges();
            return quickAdvice.Id;
        }
示例#2
0
        public ActionResult Edit(QuickAdvice model)
        {
            _repository.LangId = CurrentLangId;

            var advice = _repository.GetQuickAdvice(model.Id);
            TryUpdateModel(advice, new[] {"Title", "Active", "SortOrder"});
            advice.Text = model.Text == null ? "" : HttpUtility.HtmlDecode(model.Text);
            _repository.SaveQuickAdvice(advice);
            return RedirectToAction("Index");
        }
示例#3
0
        public ActionResult Create(QuickAdvice model)
        {
            _repository.LangId = CurrentLangId;

            var advice = new QuickAdvice()
            {
                Title = model.Title,
                Active = model.Active,
                SortOrder = model.SortOrder,
            };
            advice.Text = model.Text == null ? "" : HttpUtility.HtmlDecode(model.Text);
            _repository.AddQuickAdvice(advice);

            return RedirectToAction("Index");
        }
示例#4
0
        private void CreateOrChangeEntityLanguage(QuickAdvice cache)
        {
            var categoryLang = _store.QuickAdviceLangs.FirstOrDefault(r => r.QuickAdviceId == cache.Id && r.LanguageId == LangId);
            if (categoryLang == null)
            {
                var entityLang = new QuickAdviceLang
                {
                    QuickAdviceId = cache.Id,
                    LanguageId = LangId,

                    Title = cache.Title,
                    Text = cache.Text,
                };
                _store.QuickAdviceLangs.Add(entityLang);
            }
            else
            {
                categoryLang.Title = cache.Title;
                categoryLang.Text = cache.Text;
            }

        }
示例#5
0
 public void SaveQuickAdvice(QuickAdvice quickAdvice)
 {
     var cache = _store.QuickAdvices.SingleOrDefault(a => a.Id == quickAdvice.Id);
     CreateOrChangeEntityLanguage(cache);
     _store.SaveChanges();
 }