public ActionResult AddSermonCategory(SermonCategoryViewModel scvm)
        {
            if (ModelState.IsValid)
            {
                var existingcat = _sermonCategory.GetSermonCategories().Where(sc => sc.SermonName == scvm.SermonType.Trim()).FirstOrDefault();
                if (existingcat != null)
                {
                    ModelState.AddModelError("", "This Category name exist before");
                    return(View(scvm));
                }
                var cat = new SermonCategory
                {
                    SermonName        = scvm.SermonType,
                    Sermons           = new List <Sermon>(),
                    SermonDescription = scvm.SermonDescription
                };
                _context.SermonCategories.Add(cat);
                _context.SaveChanges();

                TempData["message"] = string.Format("{0} has been saved.", scvm.SermonType);

                return(RedirectToAction("SermonCategoryList"));
            }
            else
            {
                return(View(scvm));
            }
        }
Ejemplo n.º 2
0
 public SermonCategoryModel(SermonCategory member)
 {
     this.Assign(member);
 }