public int AddQuickAdvice(QuickAdvice quickAdvice) { _store.QuickAdvices.Add(quickAdvice); CreateOrChangeEntityLanguage(quickAdvice); _store.SaveChanges(); return quickAdvice.Id; }
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"); }
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"); }
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; } }
public void SaveQuickAdvice(QuickAdvice quickAdvice) { var cache = _store.QuickAdvices.SingleOrDefault(a => a.Id == quickAdvice.Id); CreateOrChangeEntityLanguage(cache); _store.SaveChanges(); }