public ActionResult Create(Class newClass, FormCollection collection)
        {
            //error message for section id uniqueness
            ViewData["IDerror"] = "";

            try
            {
                newClass.semster_id = collection["sem_list"];
                newClass.course_id = collection["course_list"];
                newClass.sect_id = int.Parse(collection["Classes.sect_id"]?? "0");
                newClass.room_id = collection["Classes.room_id"];
                newClass.inst_id = collection["inst_list"];
                newClass.capacity = int.Parse(collection["Classes.capacity"]);
                newClass.waitlist_capacity = int.Parse(collection["Classes.waitlist_capacity"]);
                newClass.days = (collection["days_chk"] ?? "0").Split(',').Sum(x => Int32.Parse(x));
                newClass.timeslot_id = int.Parse(collection["time_list"]);
                newClass.has_children = false;
                newClass.parent_class_id = null;

                if (db.Classes.Any(c => c.sect_id == newClass.sect_id && c.semster_id == newClass.semster_id && c.course_id == newClass.course_id))
                {
                    ViewData["IDerror"] = "Section IDs must be unique for each course ID and semester.";
                    throw new Exception();
                }

                //add new class to database and save changes
                db.AddToClasses(newClass);
                db.SaveChanges();

                //return to Index
                return RedirectToAction("Index");
            }
            catch (Exception ex)
            {
                var cur = db.Semesters.Single(s => s.semester_id == db.Current_Semester.FirstOrDefault().semester_id);

                var viewModel = new ClassManagerCreateViewModel
                {
                    Semesters = db.Semesters.Where(c => c.start_date.CompareTo(cur.start_date) >= 0).ToList(),
                    Classes = new Class(),
                    Times = db.Timeslots.ToList(),
                    Courses = db.Courses.ToList(),
                    Depts = db.Departments.ToList(),
                    Users = db.Users.Where(u => u.Role_Type.Any(r => r.role_name == "Instructor")).OrderBy(u => u.last_name).ToList()
                };

                return View(viewModel);
            }
        }
Пример #2
0
        public void AddToCart(Class class_add)
        {
            var cart_item = db.Carts.SingleOrDefault(c => c.user_id == shopping_cart_id && c.class_id == class_add.class_id && c.semester_id == class_add.semster_id);

            if (cart_item == null) {
                cart_item = new Cart
                {
                    class_id = class_add.class_id,
                    semester_id = class_add.semster_id,
                    user_id = shopping_cart_id
                };
                db.AddToCarts(cart_item);

            }
            db.SaveChanges();
        }
Пример #3
0
 /// <summary>
 /// Create a new Class object.
 /// </summary>
 /// <param name="class_id">Initial value of the class_id property.</param>
 /// <param name="semster_id">Initial value of the semster_id property.</param>
 /// <param name="course_id">Initial value of the course_id property.</param>
 /// <param name="sect_id">Initial value of the sect_id property.</param>
 /// <param name="inst_id">Initial value of the inst_id property.</param>
 /// <param name="capacity">Initial value of the capacity property.</param>
 /// <param name="waitlist_capacity">Initial value of the waitlist_capacity property.</param>
 /// <param name="has_children">Initial value of the has_children property.</param>
 public static Class CreateClass(global::System.Int32 class_id, global::System.String semster_id, global::System.String course_id, global::System.Int32 sect_id, global::System.String inst_id, global::System.Int32 capacity, global::System.Int32 waitlist_capacity, global::System.Boolean has_children)
 {
     Class @class = new Class();
     @class.class_id = class_id;
     @class.semster_id = semster_id;
     @class.course_id = course_id;
     @class.sect_id = sect_id;
     @class.inst_id = inst_id;
     @class.capacity = capacity;
     @class.waitlist_capacity = waitlist_capacity;
     @class.has_children = has_children;
     return @class;
 }
Пример #4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Classes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToClasses(Class @class)
 {
     base.AddObject("Classes", @class);
 }