Ejemplo n.º 1
0
    public void SetCriteria(Elective e)
    {
        elective = e;

        if (e.subject[0] == Subject.Any)
        {
            subject.text = "Any subject";
        }
        else
        {
            subject.text = e.subject[0].ToString();
        }

        for (int i = 1; i < e.subject.Count - 1; i++)
        {
            subject.text += ", " + e.subject[i].ToString();
        }

        if (e.level[0] == Level.Any)
        {
            level.text = "Any level";
        }
        else
        {
            level.text = e.level[0].ToString();
        }

        for (int i = 1; i < e.level.Count - 1; i++)
        {
            level.text += ", " + e.level[i].ToString();
        }
    }
Ejemplo n.º 2
0
        public ActionResult Unregister(int electiveID, int period)
        {
            ApplicationDbContext appDb = new ApplicationDbContext();
            CatalogContext       catDb = new CatalogContext();
            var userId = User.Identity.GetUserId();

            ApplicationUser appUser  = appDb.Users.Select(x => x).Where(x => x.Id == userId).FirstOrDefault();
            Elective        elective = catDb.Electives.Select(x => x).Where(x => x.ID == electiveID).FirstOrDefault();

            elective.CurrentStudentCount--;

            if (period == 1)
            {
                appUser.Elective1 = 0;
            }
            else if (period == 2)
            {
                appUser.Elective2 = 0;
            }
            else if (period == 3)
            {
                appUser.Elective3 = 0;
            }

            appDb.SaveChangesAsync();
            catDb.SaveChangesAsync();


            return(View());
        }
Ejemplo n.º 3
0
        public ActionResult Roster(int?id, int?period)
        {
            ApplicationDbContext appDb = new ApplicationDbContext();
            var students = appDb.Users.Where(s => s.Elective1 == -99); //find no students (for data type purposes)

            if (period == 1)
            {
                students = appDb.Users.Where(s => s.Elective1 == id);
            }
            if (period == 2)
            {
                students = appDb.Users.Where(s => s.Elective2 == id);
            }
            if (period == 3)
            {
                students = appDb.Users.Where(s => s.Elective3 == id);
            }

            Elective elective = db.Electives.Find(id);

            ViewBag.ElectiveName = elective.Name;
            ViewBag.PeriodNumber = period;
            ViewBag.Instructor   = elective.Instructor;

            return(View(students.ToList()));
        }
Ejemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            Elective elective = db.Electives.Find(id);

            db.Electives.Remove(elective);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "Id,Name,Description,HostId")] Elective elective)
 {
     if (ModelState.IsValid)
     {
         db.Entry(elective).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.HostId = new SelectList(db.Users, "Id", "Email", elective.HostId);
     return(View(elective));
 }
Ejemplo n.º 6
0
 public ActionResult Edit([Bind(Include = "ID,Name,Instructor,Description,Capacity,CurrentStudentCount,PeriodID")] Elective elective)
 {
     if (ModelState.IsValid)
     {
         db.Entry(elective).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PeriodID = new SelectList(db.Periods, "ID", "ID", elective.PeriodID);
     return(View(elective));
 }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "Id,Name,Description")] Elective elective)
        {
            if (ModelState.IsValid)
            {
                elective.HostId = User.Identity.GetUserId();
                db.Electives.Add(elective);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.HostId = new SelectList(db.Users, "Id", "Email", elective.HostId);
            return(View(elective));
        }
Ejemplo n.º 8
0
        // GET: Elective/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Elective elective = db.Electives.Find(id);

            if (elective == null)
            {
                return(HttpNotFound());
            }
            return(View(elective));
        }
Ejemplo n.º 9
0
        // GET: Elective/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Elective elective = db.Electives.Find(id);

            if (elective == null)
            {
                return(HttpNotFound());
            }
            ViewBag.HostId = new SelectList(db.Users, "Id", "Email", elective.HostId);
            return(View(elective));
        }
Ejemplo n.º 10
0
        // GET: Electives/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Elective elective = db.Electives.Find(id);

            if (elective == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PeriodID = new SelectList(db.Periods, "ID", "ID", elective.PeriodID);
            return(View(elective));
        }
Ejemplo n.º 11
0
        public static bool ConfirmElectivePatch_multiCourseSelect(ref CtrlElective __instance)
        {
            if (multiCourseSelect.Value)
            {
                //先排个序
                ElectiveInfosSort();

                string ids = "";
                for (int i = 0; i < selectElectiveInfos.Count; i++)
                {
                    Elective elective = selectElectiveInfos[i].Elective;
                    Game.GameData.Elective.ConfirmElective(elective.Id, elective.IsRepeat);
                    ids += selectElectiveInfos[i].Elective.Id + "_";
                }
                ids = ids.Substring(0, ids.Length - 1);
                Game.GameData.Elective.Id = ids;                //这里写的selectElectiveList存不下来,所以把所有id拼起来存到原id中,到时候拆分后用
                return(false);
            }
            return(true);
        }
Ejemplo n.º 12
0
        //
        // GET: /Manage/Index
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            ApplicationDbContext appDb = new ApplicationDbContext();
            CatalogContext       catDb = new CatalogContext();

            var userId = User.Identity.GetUserId();

            ApplicationUser appUser = appDb.Users.Select(x => x).Where(x => x.Id == userId).FirstOrDefault();

            Elective e1 = catDb.Electives.Select(x => x).Where(x => x.ID == appUser.Elective1).FirstOrDefault();
            Elective e2 = catDb.Electives.Select(x => x).Where(x => x.ID == appUser.Elective2).FirstOrDefault();
            Elective e3 = catDb.Electives.Select(x => x).Where(x => x.ID == appUser.Elective3).FirstOrDefault();

            ViewBag.User = appUser;
            ViewBag.e1   = e1;
            ViewBag.e2   = e2;
            ViewBag.e3   = e3;

            var model = new IndexViewModel
            {
                HasPassword       = HasPassword(),
                PhoneNumber       = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor         = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins            = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
            };

            return(View(model));
        }
Ejemplo n.º 13
0
        public static bool OpenConfirmWindowPatch_multiCourseSelect(ref CtrlElective __instance)
        {
            if (multiCourseSelect.Value)
            {
                UIElective view       = Traverse.Create(__instance).Field("view").GetValue <UIElective>();
                bool       IsViewMode = Traverse.Create(__instance).Field("IsViewMode").GetValue <bool>();
                if (IsViewMode)
                {
                    return(false);
                }

                string electiveNames = "";
                for (int i = 0; i < selectElectiveInfos.Count; i++)
                {
                    if (!selectElectiveInfos[i].IsConditionPass)
                    {
                        StringTable stringTable = Game.Data.Get <StringTable>("SecondaryInterface0102");
                        string      message     = (stringTable != null) ? stringTable.Text : null;


                        view.OpenConditionFailWindow(message);
                        return(false);
                    }
                    Elective elective = selectElectiveInfos[i].Elective;
                    electiveNames += elective.Name + ",";
                }
                StringTable stringTable2 = Game.Data.Get <StringTable>("SecondaryInterface0101");
                string      text         = (stringTable2 != null) ? stringTable2.Text : null;
                electiveNames = electiveNames.Substring(0, electiveNames.Length - 1);
                text          = (text.IsNullOrEmpty() ? string.Empty : string.Format(text, electiveNames));
                view.OpenConfirmWindow(text);

                return(false);
            }
            return(true);
        }
Ejemplo n.º 14
0
        public List <Elective> FindSSElectives(string tableName)
        {
            String          query;
            List <Elective> result = new List <Elective>();
            DataTable       Computer_Engineering_Courses;

            List <Course> nonhist = new List <Course>();

            Elective history = new Elective("History", 9);
            Elective ss      = new Elective("Humanities", 9);

            query = "SELECT * FROM " + tableName + "_SSElectives";
            Computer_Engineering_Courses = GraduationPlanningSystem.db.queryDB(query);
            foreach (DataRow req_course in Computer_Engineering_Courses.Select())
            {
                // this should give you the uid of each course in the Computer_Engineering_Req table
                String course_uid = (String)req_course[0];
                Course course     = new Course(course_uid, Course.AcademicStatus.NotYetTaken);

                if (course.Name != "" && course.Name != null)
                {
                    if (course.Department == "History")
                    {
                        history.Courses.Add(course);
                    }
                    else
                    {
                        ss.Courses.Add(course);
                    }
                }
            }

            result.Add(history);
            result.Add(ss);
            return(result);
        }
Ejemplo n.º 15
0
        public JsonResult SaveCourseSelection(List <CourseListsByCartsByCourseWork> deleteByCartOkCopy, List <CourseListsByCartsByCourseWork> courseListsByCarts)
        {
            try
            {
                if (deleteByCartOkCopy == null && courseListsByCarts == null)
                {
                    return(Json(new { message = "選課成功~" }));
                }

                SchoolContext db      = new SchoolContext();
                string        loginId = Session["sIDNo"].ToString();
                var           student = db.Student.FirstOrDefault(x => x.LogonId == loginId);

                if (courseListsByCarts != null)
                {
                    string subjectNumberString = "";
                    foreach (var clbc in courseListsByCarts)
                    {
                        var course        = db.Course.FirstOrDefault(x => x.CourseID == clbc.CourseId);
                        var courseMax     = course.MaxNumber;
                        var electiveCount = db.Elective.Where(x => x.CourseId == clbc.CourseId).Count() + 1; //1是指測試增加1個學生會不會超過最大數量

                        if (electiveCount > courseMax)
                        {
                            subjectNumberString += clbc.SubjectNumber + "、";
                        }
                    }

                    if (subjectNumberString != "")
                    {
                        throw new Exception(subjectNumberString.Substring(0, subjectNumberString.Length - 1) + "名額已滿,請把已滿的課程做取消,否則無法繼續下一步!!!");
                    }

                    foreach (var clbc in courseListsByCarts)
                    {
                        var course = db.Course.FirstOrDefault(x => x.CourseID == clbc.CourseId);

                        Elective electiveDto = new Elective();
                        electiveDto.StartingSchoolYear = course.StartingSchoolYear;
                        electiveDto.Semester           = course.Semester;
                        electiveDto.Credits            = course.Credits;
                        electiveDto.CourseId           = clbc.CourseId;
                        electiveDto.LogonId            = student.LogonId;
                        electiveDto.StudentId          = student.ID;
                        db.Elective.Add(electiveDto);
                        db.SaveChanges();
                        int electiveId = db.Elective.OrderByDescending(x => x.ID).ToList()[0].ID;

                        ElectiveLog electiveLogDto = new ElectiveLog();
                        electiveLogDto.Remarks            = "學生自行選課";
                        electiveLogDto.CreatedUserId      = student.ID;
                        electiveLogDto.CreateDate         = DateTime.Now;
                        electiveLogDto.StartingSchoolYear = course.StartingSchoolYear;
                        electiveLogDto.Semester           = course.Semester;
                        electiveLogDto.Credits            = course.Credits;
                        electiveLogDto.CourseId           = clbc.CourseId;
                        electiveLogDto.LogonId            = student.LogonId;
                        electiveLogDto.StudentId          = student.ID;
                        electiveLogDto.ElectiveId         = electiveId;
                        db.ElectiveLog.Add(electiveLogDto);
                        db.SaveChanges();

                        var electiveCount = db.Elective.Where(x => x.CourseId == clbc.CourseId).Count();
                        var courseStatus  = db.CourseStatus.FirstOrDefault(x => x.CourseId == clbc.CourseId);
                        courseStatus.CurrentQuota = electiveCount;
                        db.SaveChanges();
                    }
                }

                if (deleteByCartOkCopy != null)
                {
                    foreach (var dc in deleteByCartOkCopy)
                    {
                        var elective = db.Elective.FirstOrDefault(x => x.ID == dc.ElectiveId);
                        var CourseId = elective.CourseId;

                        ElectiveLog electiveLogDto = new ElectiveLog();
                        electiveLogDto.Remarks            = "學生自行刪除";
                        electiveLogDto.CreatedUserId      = student.ID;
                        electiveLogDto.CreateDate         = DateTime.Now;
                        electiveLogDto.StartingSchoolYear = elective.StartingSchoolYear;
                        electiveLogDto.Semester           = elective.Semester;
                        electiveLogDto.Credits            = elective.Credits;
                        electiveLogDto.CourseId           = elective.CourseId;
                        electiveLogDto.LogonId            = elective.LogonId;
                        electiveLogDto.StudentId          = elective.StudentId;
                        electiveLogDto.ElectiveId         = elective.ID;
                        db.ElectiveLog.Add(electiveLogDto);
                        db.SaveChanges();

                        db.Elective.Remove(elective);
                        db.SaveChanges();

                        var electiveCount = db.Elective.Where(x => x.CourseId == CourseId).Count();
                        var courseStatus  = db.CourseStatus.FirstOrDefault(x => x.CourseId == CourseId);
                        courseStatus.CurrentQuota = electiveCount;
                        db.SaveChanges();
                    }
                }

                return(Json(new { message = "選課成功~" }));
            }
            catch (Exception ex)
            {
                return(Json(new { message = ex.Message, error = false }));
            }
        }
Ejemplo n.º 16
0
        public ActionResult Register(int electiveID, int period, int?id)
        {
            ApplicationDbContext appDb = new ApplicationDbContext();
            CatalogContext       catDb = new CatalogContext();
            var userId = User.Identity.GetUserId();

            ApplicationUser appUser  = appDb.Users.Select(x => x).Where(x => x.Id == userId).FirstOrDefault();
            Elective        elective = catDb.Electives.Select(x => x).Where(x => x.ID == id).FirstOrDefault();

            if (period == 1)
            {
                if (appUser.Elective1 == 0 && elective.CurrentStudentCount < elective.Capacity)
                {
                    appUser.Elective1 = electiveID;
                    ViewBag.Message   = "Successful registration!";
                    elective.CurrentStudentCount++;
                }
                else if (elective.CurrentStudentCount >= elective.Capacity)
                {
                    ViewBag.Message = "Sorry, that class is now full";
                }
                else
                {
                    ViewBag.Message = "Sorry registration failed, you already have an elective selected for that period";
                }
            }
            else if (period == 2)
            {
                if (appUser.Elective2 == 0 && elective.CurrentStudentCount < elective.Capacity)
                {
                    appUser.Elective2 = electiveID;
                    ViewBag.Message   = "Successful registration!";
                    elective.CurrentStudentCount++;
                }
                else if (elective.CurrentStudentCount >= elective.Capacity)
                {
                    ViewBag.Message = "Sorry, that class is now full";
                }
                else
                {
                    ViewBag.Message = "Sorry registration failed, you already have an elective selected for that period";
                }
            }
            else
            {
                if (appUser.Elective3 == 0 && elective.CurrentStudentCount < elective.Capacity)
                {
                    appUser.Elective3 = electiveID;
                    ViewBag.Message   = "Successful registration!";
                    elective.CurrentStudentCount++;
                }
                else if (elective.CurrentStudentCount >= elective.Capacity)
                {
                    ViewBag.Message = "Sorry, that class is now full";
                }
                else
                {
                    ViewBag.Message = "Sorry registration failed, you already have an elective selected for that period";
                }
            }

            appDb.SaveChangesAsync();
            catDb.SaveChangesAsync();

            return(View());
        }