Exemplo n.º 1
0
        //
        // GET: /SubjectRegistration/Create

        public ActionResult Create()
        {
            SubRegistrationViewModel model       = new SubRegistrationViewModel();
            SubjectRegistration      thesubReg   = new SubjectRegistration();
            List <Subject>           theSubjects = work.SubjectRepository.Get().OrderBy(a => a.Name).ToList();

            model.Subjects            = theSubjects;
            model.SubjectRegistration = thesubReg;


            Dictionary <string, string> theDic  = new Dictionary <string, string>();
            List <SelectListItem>       theItem = new List <SelectListItem>();
            List <Subject> theSub = work.SubjectRepository.Get().OrderBy(a => a.Name).ToList();

            foreach (var subject in theSub)
            {
                theItem.Add(new SelectListItem()
                {
                    Text = subject.Name, Value = subject.Name
                });
            }

            //  theItem.Add(new SelectListItem() { Text = "PRIMART 1A", Value = "PRIMART 1A" });
            ViewBag.Subjects = theItem;
            ViewBag.Subject  = theSub;
            return(View(model));
        }
Exemplo n.º 2
0
        //
        // GET: /SubjectRegistration/

        // public ActionResult Index()
        public ActionResult Index(string sortOrder, string currentFilter, int?page)
        {
            int pageSize   = 30;
            int pageNumber = (page ?? 1);
            SubRegistrationViewModel model       = new SubRegistrationViewModel();
            List <Subject>           theSubjects = work.SubjectRepository.Get().ToList();

            model.Subjects = theSubjects;

            ViewBag.Count = work.SubjectRegistrationRepository.Get().Count();

            List <SubjectRegistration> theSubReg = work.SubjectRegistrationRepository.Get().ToList();

            return(View(theSubReg.ToPagedList(pageNumber, pageSize)));
            //  return View(theSubReg);
        }
Exemplo n.º 3
0
        public ActionResult Create(SubRegistrationViewModel model, string[] SubjectRegistration)
        {
            try
            {
                if (SubjectRegistration == null || model.Level == null)
                {
                    // SubRegistrationViewModel model = new SubRegistrationViewModel();
                    SubjectRegistration thesubReg   = new SubjectRegistration();
                    List <Subject>      theSubjects = work.SubjectRepository.Get().OrderBy(a => a.Name).ToList();
                    model.Subjects            = theSubjects;
                    model.SubjectRegistration = thesubReg;


                    Dictionary <string, string> theDic  = new Dictionary <string, string>();
                    List <SelectListItem>       theItem = new List <SelectListItem>();
                    List <Subject> theSub = work.SubjectRepository.Get().OrderBy(a => a.Name).ToList();
                    foreach (var subject in theSub)
                    {
                        theItem.Add(new SelectListItem()
                        {
                            Text = subject.Name, Value = subject.Name
                        });
                    }

                    //  theItem.Add(new SelectListItem() { Text = "PRIMART 1A", Value = "PRIMART 1A" });
                    ViewBag.Subjects = theItem;
                    ViewBag.Subject  = theSub;
                    ModelState.AddModelError("", "Select at least one Subject to a given Class");
                    //////
                    return(View(model));
                }

                else
                {
                    List <SubjectRegistration> theRegSub = work.SubjectRegistrationRepository.Get(a => a.Level == model.Level).ToList();

                    if (theRegSub.Count > 0)
                    {
                        // SubRegistrationViewModel model = new SubRegistrationViewModel();
                        SubjectRegistration thesubReg   = new SubjectRegistration();
                        List <Subject>      theSubjects = work.SubjectRepository.Get().OrderBy(a => a.Name).ToList();
                        model.Subjects            = theSubjects;
                        model.SubjectRegistration = thesubReg;


                        Dictionary <string, string> theDic  = new Dictionary <string, string>();
                        List <SelectListItem>       theItem = new List <SelectListItem>();
                        List <Subject> theSub = work.SubjectRepository.Get().OrderBy(a => a.Name).ToList();
                        foreach (var subject in theSub)
                        {
                            theItem.Add(new SelectListItem()
                            {
                                Text = subject.Name, Value = subject.Name
                            });
                        }

                        //  theItem.Add(new SelectListItem() { Text = "PRIMART 1A", Value = "PRIMART 1A" });
                        ViewBag.Subjects = theItem;
                        ViewBag.Subject  = theSub;
                        ModelState.AddModelError("", "Class Subjects for Selected Class has been Created Earlier");
                        return(View(model));
                    }
                    // TODO: Add insert logic here

                    List <Subject> theSubjects4 = new List <Subject>();
                    List <Subject> theSubjects2 = new List <Subject>();
                    foreach (var sub in SubjectRegistration)
                    {
                        theSubjects2 = work.SubjectRepository.Get(a => a.Name.Equals(sub)).ToList();
                        theSubjects4.Add(theSubjects2[0]);
                    }

                    SubjectRegistration theRealSub = new SubjectRegistration();
                    theRealSub.Level    = model.Level;
                    theRealSub.Subjects = theSubjects4;
                    work.SubjectRegistrationRepository.Insert(theRealSub);
                    work.Save();

                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                return(View());
            }
        }