Exemplo n.º 1
0
        public ActionResult Edit(int id, AuthorCategory model)
        {
            try
            {
                var tag = _context.AuthorCategories.FirstOrDefault(t => t.Id == id);
                if (tag != null)
                {
                    tag.Title = model.Title;
                    tag.TitleEn = model.TitleEn;
                    tag.TitleUa = model.TitleUa;
                    tag.SortOrder = model.SortOrder;
                    _context.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                TempData["errorMessage"] = ex.GetEntityValidationException();

                if (string.IsNullOrEmpty((string)TempData["errorMessage"]))
                {
                    TempData["errorMessage"] = ex.Message;
                }
                return View(model);
            }
        }
Exemplo n.º 2
0
        public ActionResult Create(AuthorCategory model)
        {
            try
            {
                var category = new AuthorCategory
                {
                    Title = model.Title,
                    TitleEn = model.TitleEn,
                    TitleUa = model.TitleUa,
                    SortOrder = model.SortOrder
                };

                _context.AuthorCategories.Add(category);
                _context.SaveChanges();

                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                TempData["errorMessage"] = ex.GetEntityValidationException();

                if (string.IsNullOrEmpty((string)TempData["errorMessage"]))
                {
                    TempData["errorMessage"] = ex.Message;
                }
                return View(model);
            }
        }