public ActionResult Create(SectionViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    tb_section section = new tb_section
                    {
                        section_title       = model.section_title,
                        section_description = model.section_description
                    };

                    sectionRepository.Add(section);
                    sectionRepository.Save();
                    @ViewBag.Message = "<div class=\"alert alert-success\">!! La section a ete sauvegardee avec succes </div>";
                    //use tempdata
                    return(RedirectToAction("Index", "Section"));
                }
                catch (Exception exp)
                {
                    ViewBag.Message = exp.Message;
                }
            }

            return(View(model));
        }
        public ActionResult Edit(int id)
        {
            tb_section section = sectionRepository.GetById(id);

            if (section != null)
            {
                return(View(section));
            }
            return(RedirectToAction("Index", "Section"));
        }
        public ActionResult Delete(int id)
        {
            tb_section section = sectionRepository.GetById(id);

            if (section != null)
            {
                sectionRepository.Delete(section);
                sectionRepository.Save();
                @ViewBag.Message = "<div class=\"alert alert-success\">La section a ete supprimee avec succes </div>";
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(tb_section model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    sectionRepository.Update(model);
                    sectionRepository.Save();
                    @ViewBag.Message = "<div class=\"alert alert-success\">!! La section a ete sauvegardee avec succes </div>";
                    return(RedirectToAction("Index", "Section"));
                }
                catch (Exception exp)
                {
                    ViewBag.Message = exp.Message;
                }
            }

            return(View(model));
        }
Beispiel #5
0
        public SectionModel Create(tb_section section)
        {
            List <CategoryModel> category = new List <CategoryModel>();

            foreach (var cat in section.tb_category)
            {
                category.Add(new CategoryModel {
                    id_category    = cat.id_category,
                    category_title = cat.category_title,
                    category_order = cat.category_order
                });
            }
            ;

            return(new SectionModel {
                id_section = section.id_section,
                section_title = section.section_title,
                categories = category
            });
        }