Exemplo n.º 1
0
        public ActionResult Add([Bind(Exclude = "streamId")] SubjectViewModel subjectViewModel, bool another)
        {
            if (ModelState.IsValid)
            {
                string userId = User.Identity.GetUserId();
                var    user   = db.Managers.Find(userId);
                var    stream = user.school.Streams.ToList().Find(p => p.name == "Grade 8 & 9");
                var    exist  = stream.subjects.ToList().Find(p => p.name.ToLower() == subjectViewModel.name.ToLower());
                if (exist != null)
                {
                    ModelState.AddModelError("", subjectViewModel.name + " already exists.");
                    return(View(subjectViewModel));
                }
                var subject = new Subject {
                    name = subjectViewModel.name, stream = stream, streamId = "0"
                };

                if (stream.enrollments.Any())
                {
                    foreach (var i in stream.enrollments)
                    {
                        var subj = new EnrollmentSubject
                        {
                            name       = subject.name,
                            Enrollment = i
                        };
                        db.EnrollmentSubjects.Add(subj);
                    }
                }
                db.Subjects.Add(subject);
                db.SaveChanges();
                if (another == true)
                {
                    return(RedirectToAction("Add", "Subjects"));
                }
                return(RedirectToAction("Add", "Enrollments"));
            }
            return(View(subjectViewModel));
        }
Exemplo n.º 2
0
 public ActionResult Add(bool another, Enrollment8to9ViewModel enrollment8to9ViewModel)
 {
     if (ModelState.IsValid)
     {
         string userId = User.Identity.GetUserId();
         var    user   = db.Managers.Find(userId);
         var    stream = user.school.Streams.ToList().Find(p => p.name == "Grade 8 & 9");
         enrollment8to9ViewModel.group = enrollment8to9ViewModel.group.ToUpper();
         var enroll = stream.enrollments.ToList().Find(p => p.grade == enrollment8to9ViewModel.grade && p.group == enrollment8to9ViewModel.group);
         if (enroll != null)
         {
             ModelState.AddModelError("", "Grade " + enrollment8to9ViewModel.grade + enrollment8to9ViewModel.group + " already exists.");
             return(View(enrollment8to9ViewModel));
         }
         var enrollment = new Enrollment {
             grade = enrollment8to9ViewModel.grade, group = enrollment8to9ViewModel.group, stream = stream
         };
         foreach (var i in stream.subjects)
         {
             var subject = new EnrollmentSubject
             {
                 name       = i.name,
                 Enrollment = enrollment
             };
             db.EnrollmentSubjects.Add(subject);
         }
         db.Enrollments.Add(enrollment);
         db.SaveChanges();
         if (another == true)
         {
             return(RedirectToAction("Add", "Enrollments"));
         }
         return(RedirectToAction("Index", "Home"));
     }
     return(View(enrollment8to9ViewModel));
 }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Include = "Id,name,streamId")] bool another, Subject subject)
        {
            string userId = User.Identity.GetUserId();
            var    user   = db.Managers.Find(userId);

            if (!ModelState.IsValid)
            {
                var streamList  = new List <SelectListItem>();
                var streamQuery = from e in user.school.Streams
                                  where e.name != "Grade 8 & 9"
                                  select e;
                foreach (var m in streamQuery)
                {
                    streamList.Add(new SelectListItem {
                        Value = (m.Id).ToString(), Text = m.name
                    });
                }
                ViewBag.streamlist = streamList;

                return(View(subject));
            }
            if (ModelState.IsValid)
            {
                var StrId  = Convert.ToInt64(subject.streamId);
                var stream = user.school.Streams.ToList().Find(p => p.Id == StrId);
                var exist  = stream.subjects.ToList().Find(p => p.name.ToLower() == subject.name.ToLower());
                if (exist != null)
                {
                    ModelState.AddModelError("", subject.name + " already exists under " + exist.stream.name + " Stream.");
                    var streamList  = new List <SelectListItem>();
                    var streamQuery = from e in user.school.Streams
                                      where e.name != "Grade 8 & 9"
                                      select e;
                    foreach (var m in streamQuery)
                    {
                        streamList.Add(new SelectListItem {
                            Value = (m.Id).ToString(), Text = m.name
                        });
                    }
                    ViewBag.streamlist = streamList;

                    return(View(subject));
                }
                if (stream.enrollments.Any())
                {
                    foreach (var i in stream.enrollments)
                    {
                        var subj = new EnrollmentSubject
                        {
                            name       = subject.name,
                            Enrollment = i
                        };
                        db.EnrollmentSubjects.Add(subj);
                    }
                }
                subject.stream = stream;
                db.Subjects.Add(subject);
                db.SaveChanges();
                if (another == true)
                {
                    return(RedirectToAction("Create"));
                }
                return(RedirectToAction("Create", "Enrollments"));
            }
            return(View(subject));
        }
Exemplo n.º 4
0
        public ActionResult Create([Bind(Include = "Id,grade,group,streamId")] bool another, Enrollment10to12ViewModel enrollment10to12ViewModel)
        {
            string userId = User.Identity.GetUserId();
            var    user   = db.Managers.Find(userId);

            if (!ModelState.IsValid)
            {
                var streamList  = new List <SelectListItem>();
                var streamQuery = from e in user.school.Streams
                                  where e.name != "Grade 8 & 9"
                                  select e;
                foreach (var m in streamQuery)
                {
                    streamList.Add(new SelectListItem {
                        Value = (m.Id).ToString(), Text = m.name
                    });
                }
                ViewBag.streamlist = streamList;

                return(View(enrollment10to12ViewModel));
            }
            if (ModelState.IsValid)
            {
                var StrId  = Convert.ToInt64(enrollment10to12ViewModel.streamId);
                var stream = user.school.Streams.ToList().Find(p => p.Id == StrId);
                enrollment10to12ViewModel.group = enrollment10to12ViewModel.group.ToUpper();
                var exist = stream.enrollments.ToList().Find(p => p.grade == enrollment10to12ViewModel.grade && p.group == enrollment10to12ViewModel.group);
                if (exist != null)
                {
                    ModelState.AddModelError("", "Grade " + enrollment10to12ViewModel.grade + enrollment10to12ViewModel.group + " already exists.");
                    var streamList  = new List <SelectListItem>();
                    var streamQuery = from e in user.school.Streams
                                      where e.name != "Grade 8 & 9"
                                      select e;
                    foreach (var m in streamQuery)
                    {
                        streamList.Add(new SelectListItem {
                            Value = (m.Id).ToString(), Text = m.name
                        });
                    }
                    ViewBag.streamlist = streamList;

                    return(View(enrollment10to12ViewModel));
                }
                var enrollment = new Enrollment {
                    grade = enrollment10to12ViewModel.grade, group = enrollment10to12ViewModel.group, stream = stream
                };
                foreach (var i in stream.subjects)
                {
                    var subject = new EnrollmentSubject
                    {
                        name       = i.name,
                        Enrollment = enrollment
                    };
                    db.EnrollmentSubjects.Add(subject);
                }
                db.Enrollments.Add(enrollment);
                db.SaveChanges();
                if (another == true)
                {
                    return(RedirectToAction("Create"));
                }
                return(RedirectToAction("Index", "Home"));
            }

            return(View(enrollment10to12ViewModel));
        }