public List<course> getAllCourses() { List<course> courses = null; using(SqlConnection con = connectionManager.getConnection()) { using(SqlCommand com = new SqlCommand("getAllCourses",con)) { com.CommandType = System.Data.CommandType.StoredProcedure; try { con.Open(); SqlDataReader reader = com.ExecuteReader(); if(reader.HasRows) { courses = new List<course>(); while(reader.Read()) { course course = new course(); course.id = Convert.ToInt32(reader["id"]); course.datumVan = Convert.ToDateTime(reader["datum_van"]).ToShortDateString(); course.datumTot = Convert.ToDateTime(reader["datum_tot"]).ToShortDateString(); course.startuur = Convert.ToInt32(reader["startuur"]); course.einduur = Convert.ToInt32(reader["einduur"]); course.maxDeelnemers = Convert.ToInt32(reader["max_deelnemers"]); course.kostprijs = Convert.ToInt32(reader["kostprijs"]); course.naam = reader["cursusNaam"].ToString(); course.omschrijving = reader["omschrijving"].ToString(); course.leeftijdVanaf = Convert.ToInt32(reader["leeftijd_vanaf"]); course.leeftijdTotEnMet = Convert.ToInt32(reader["leeftijd_tot_en_met"]); course.fotoLink = reader["foto_link"].ToString(); course.locatieNaam = reader["locatieNaam"].ToString(); course.locatieAdres = reader["locatieAdres"].ToString(); courses.Add(course); }; }; } catch(Exception ex) { return new List<course>() { new course() { naam = "error", locatieNaam = ex.Message } }; }; } } return courses; }
protected void lbtndel_Click(object sender, EventArgs e) { int j = 0; for (int i = 0; i < gvcourse.Rows.Count; i++) { CheckBox cb = (CheckBox)gvcourse.Rows[i].FindControl("cbsel"); if (cb.Checked) { j = j + 1; int id = int.Parse(gvcourse.DataKeys[i].Value.ToString()); course myCourse = new course(); myCourse.DeleteCourse(id); } } if (j == 0) { Response.Write("<script>alert('请选择要删除的课程')</script>"); } else { BindData(); } }
private void button1_Click(object sender, EventArgs e) { linqtoregdbDataContext db = new linqtoregdbDataContext(); if (comboBox1.SelectedIndex == -1) { MessageBox.Show("Please select an instructor!"); } else if (maskedTextBox3.Text == "") { MessageBox.Show("Please enter a course name."); } else if (textBox2.Text == "") { MessageBox.Show("Please enter a course title."); } else if (listBox1.Items.Count == 0) { MessageBox.Show("Please add at least one time block."); } else if (!maskedTextBox3.MaskCompleted) { MessageBox.Show("Course name not in acceptable format."); } else { string courseNameToAdd = maskedTextBox3.Text; if (courseNameToAdd[0] == ' ') { courseNameToAdd = courseNameToAdd.Substring(1, courseNameToAdd.Length - 1); } try { var queryFacID = (from usr in db.users where usr.username == comboBox1.Text select usr.userID).FirstOrDefault(); course addCourse = new course { instructor = queryFacID, courseTitle = textBox2.Text, courseName = courseNameToAdd, numSeats = (int)numericUpDown2.Value, courseCredit = numericUpDown1.Value, semester = "S15" }; db.courses.InsertOnSubmit(addCourse); db.SubmitChanges(); var queryNewCourseID = (from crs in db.courses where crs.courseName == courseNameToAdd select crs.courseID).FirstOrDefault(); int numTimeBlocks = listBox1.Items.Count; for (int i = 0; i < numTimeBlocks; i++) { course_timeblock crstb = new course_timeblock { courseID = queryNewCourseID, timeblock = timeblocks[0] }; db.course_timeblocks.InsertOnSubmit(crstb); timeblocks.RemoveAt(0); listBox1.Items.RemoveAt(0); } db.SubmitChanges(); MessageBox.Show("Course added successfully!"); this.Close(); } catch (Exception) { MessageBox.Show("Error: Invalid course name."); } try { foreach (var c in listBox2.Items) { db.prereqs.InsertOnSubmit(new prereq { courseName = courseNameToAdd, prereqName = c.ToString() }); } db.SubmitChanges(); this.Close(); } catch (Exception) { MessageBox.Show("Error adding prerequisites. Course added successfully. Edit prerequisites in the Edit Courses menu."); this.Close(); } } }
public IActionResult PutById([FromBody] course cr) { cr.Name = "这是Put"; return(Json(cr)); }
public IHttpActionResult TestPost(course course) { //string imageName = null; //var httpRequest = HttpContext.Current.Request; //var postFile = httpRequest.Files[0]; //imageName = new String(Path.GetFileNameWithoutExtension(postFile.FileName).Take(10).ToArray()).Replace(" ", "-"); //imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postFile.FileName); //var filePath = HttpContext.Current.Server.MapPath("~/Images/" + imageName); //postFile.SaveAs(filePath); string imageName = null; var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; var filePath = HttpContext.Current.Server.MapPath("~/" + postedFile.FileName); imageName = postedFile.FileName; postedFile.SaveAs(filePath); } } Guid originalGuid = Guid.NewGuid(); string guild = originalGuid.ToString("D"); Guid newGuid = Guid.Parse(guild); var result = from a in db.courses join b in db.skills on a.idskill equals b.idskill join c in db.trainees on a.trainee_course equals c.traineeid join d in db.categories on b.categoryid equals d.categoryid where b.idskill == a.idskill && c.traineeid == a.trainee_course select a; foreach (var item in result) { if (item.idskill == course.idskill) { return(BadRequest()); } } db.courses.Add(new course { courseid = newGuid.ToString(), title = course.title, description = course.description, city = course.city, address = course.address, time = course.time, createddate = DateTime.UtcNow.Date, status = 0, idskill = course.idskill, trainee_course = course.trainee_course, isnotification = 1, image_course = imageName, }); db.SaveChanges(); return(CreatedAtRoute("TestPost", new { id = course.courseid }, course)); }
static void Main(string[] args) { course ele = new course(); ele.getdetails(); }
public async Task <IHttpActionResult> Postcourse(course course) { // course.instructor= if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Course_Members cm = new Course_Members(); course_tags ct = new course_tags(); ct.course_id = course.id; //ct.tag_id= cm.Course_id = course.id; cm.Member_id = course.instructor; cm.AddingDate = course.creating_date; //send notification to all friends var friends = db.friends.Where(x => x.UserId == course.instructor && x.Confirmed == true).Select(x => x.friendId); var friends2 = db.friends.Where(x => x.friendId == course.instructor && x.Confirmed == true).Select(x => x.UserId); friends.Concat(friends2); // var new_notifi = new cls_notifi { source_name = "course", source_id = db.courses.OrderByDescending(x => x.id).FirstOrDefault().id.ToString(), image = "no image", body_English = "Course " + course.name + " is available now by your friend " + db.AspNetUsers.FirstOrDefault(x => x.Id == course.instructor).UserName, body_Arabic = "تمت اتاحة كورس " + course.name + " من قبل صديقك " + db.AspNetUsers.FirstOrDefault(x => x.Id == course.instructor).UserName, timestamp = DateTime.UtcNow, readed = false }; foreach (var item in friends) { await Push(new_notifi, "notifications/" + item + "/" + DateTime.UtcNow.ToString("dd-MM-yyyy")); PushNotifi(db.AspNetUsers.FirstOrDefault(x => x.Id == item).DeviceToken, "New Course", new_notifi.body_English, "course", db.courses.OrderByDescending(x => x.id).FirstOrDefault().id.ToString()); } /////// Add Chat Room for the Course /////////////////////////////////////////////////////////// IFirebaseClient client = new FirebaseClient(config); cls_room new_room = new cls_room { name = course.name, about = "Chat Room for " + course.name + " Course", admin = course.instructor, photo = "" }; PushResponse response = await client.PushAsync("chat/rooms/", new_room); var xcv = response.Result.name; var firstMem = new { mem_id = course.instructor, //db.AspNetUsers.FirstOrDefault(x => x.UserName == room.adminName).Id, mem_name = db.AspNetUsers.FirstOrDefault(x => x.Id == course.instructor).UserName //room.adminName }; await PushChat(firstMem, "chat/members/" + xcv); ///////////////////////////// var new_room2 = new { RoomId = xcv, RoomName = new_room.name, about = "Chat room for " + course.name + " course", AddedOn = DateTime.UtcNow, RoomType = "course", RelatedTypeId = db.courses.OrderByDescending(x => x.id).FirstOrDefault().id }; await PushChat(new_room2, "chat/memberRooms/" + course.instructor); course.room_id = xcv; db.courses.Add(course); db.Course_Members.Add(cm); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = course.id }, course)); }
public ActionResult AddCourse() { course model = new course(); return(View(model)); }
public string Post([FromBody] JObject jObj) { DBEntities db = new DBEntities(); List <usr> uData = db.usr.ToList(); List <course> cData = db.course.ToList(); List <uc> ucData = db.uc.ToList(); string type = jObj["type"].ToString(); //客户端操作类型 if (type.Equals("login")) { string inNo = jObj["no"].ToString(); string inPw = jObj["pw"].ToString(); //匹配成功,返回users的id,密码错误返回-1, 账号不存在返回0 for (int i = 0; i < uData.Count; i++) { if (uData[i].no == inNo) { if (uData[i].pw == inPw) { return(uData[i].uid.ToString()); } else { return("-1"); } } } return("0"); } else if (type.Equals("register")) { string no = jObj["no"].ToString(); string pw = jObj["pw"].ToString(); string school = jObj["school"].ToString(); string major = jObj["major"].ToString(); usr uTmp = db.usr.Where(usr => usr.no == no).FirstOrDefault(); if (uTmp == null) { usr u = new usr() { no = no, pw = pw, school = school, major = major }; db.usr.Add(u); if (db.SaveChanges() > 0) { return("1"); } return("-1"); } else { return("0"); } } else if (type.Equals("getCourseInfo")) { int uid = int.Parse(jObj["uid"].ToString()); //得到客户端当前登录用户的id List <course> cUidData = new List <course>(); //储存匹配到的当前用户的课程信息 for (int i = 0; i < ucData.Count; i++) { if (ucData[i].uid == uid) { for (int j = 0; j < cData.Count; j++) { if (cData[j].cid == ucData[i].cid) { course c = new course(); //一条课程记录 c.cid = cData[j].cid; c.coursename = cData[j].coursename; c.teacher = cData[j].teacher; c.classroom = cData[j].classroom; c.classstart = cData[j].classstart; c.classend = cData[j].classend; c.day = cData[j].day; cUidData.Add(c); } } } } return(JsonConvert.SerializeObject(cUidData)); } else if (type.Equals("addCourse") || type.Equals("editCourse") || type.Equals("delCourse")) { int uid = int.Parse(jObj["uid"].ToString()); //得到当前用户的id int cid = int.Parse(jObj["cid"].ToString()); //得到课程id,若type为edit则为修改前的id,若为del则为要删除的id, 若为add则为0(防止空指针异常) if (type.Equals("delCourse")) //删除操作 { uc ucTmp = db.uc.Where(uc => uc.uid == uid && uc.cid == cid).FirstOrDefault(); db.uc.Remove(ucTmp); } else { //得到修改后的课程 string cn = jObj["coursename"].ToString(); string tn = jObj["teacher"].ToString(); string cr = jObj["classroom"].ToString(); int cs = int.Parse(jObj["classstart"].ToString()); int ce = int.Parse(jObj["classend"].ToString()); int day = int.Parse(jObj["day"].ToString()); if (type.Equals("addCourse")) //若添加的课程与已存在的课程时间段有重合,则添加失败 { List <course> cSEList = db.course.Where(course => course.classstart >= cs && course.classend <= ce && course.day == day).ToList(); List <uc> ucUidList = db.uc.Where(uc => uc.uid == uid).ToList(); for (int i = 0; i < cSEList.Count; i++) { for (int j = 0; j < ucUidList.Count; j++) { if (cSEList[i].cid == ucUidList[j].cid) { return("0"); } } } } course cTmp1 = db.course.Where(course => course.coursename == cn && course.teacher == tn && course.classroom == cr && course.classstart == cs && course.classend == ce && course.day == day ).FirstOrDefault(); course c = new course(); course cTmp2 = new course(); if (cTmp1 == null) { cTmp2.coursename = cn; cTmp2.teacher = tn; cTmp2.classroom = cr; cTmp2.classstart = cs; cTmp2.classend = ce; cTmp2.day = day; db.course.Add(cTmp2); db.SaveChanges(); c = cTmp2; } else { c = cTmp1; } if (type.Equals("addCourse")) //添加操作 { uc ucTmp = new uc() { uid = uid, cid = c.cid }; db.uc.Add(ucTmp); } else if (type.Equals("editCourse")) //编辑操作 { uc ucUid = db.uc.Where(uc => uc.uid == uid && uc.cid == cid).FirstOrDefault(); ucUid.cid = c.cid; } cid = c.cid; //便于返回cid } if (db.SaveChanges() > 0) { return(cid.ToString()); } return("0"); } return("0"); }
public ActionResult Save(course stu) { tb.courses.AddOrUpdate(stu); tb.SaveChanges(); return(RedirectToAction("coures", "Home")); }
public ActionResult Add(course stu) { return(View("Add")); }
public void Create(course co) { db.courses.Add(co); db.SaveChanges(); }
public void addCourse(course course) { CourseContext.AddOne(course); }
public ActionResult Edit([Bind(Include = "id,code,title,hours,class_length,have_final_exam,exam_length,program_id," + "is_deleted,created_by,class_weekday,class_start_time,room_id,faculty_id,program_id")] course course) { if (ModelState.IsValid) { db.Entry(course).State = EntityState.Modified; course.modified_on = DateTime.Now; course_exam tempCEX = db.course_exam.Where(w => w.course_id == course.id).First(); tempCEX.exam_length = course.exam_length; tempCEX.final_exam_note = course.final_exam_note; tempCEX.modified_on = DateTime.Now; section tempS = db.sections.Where(w => w.course_id == course.id).First(); tempS.program_id = course.program_id; tempS.faculty_id = course.faculty_id; tempS.class_weekday = course.class_weekday; tempS.class_start_time = course.class_start_time; tempS.room_id = course.room_id; tempS.modified_on = DateTime.Now; if (course.is_deleted == true) { // set this course-exam is_deleted = true var tempCE = db.course_exam.Where(e => e.course_id == course.id); if (tempCE.ToList().Count > 0) { foreach (var item in tempCE) { item.is_deleted = true; } } // set this course - section is_deleted = true var tempCS = db.sections.Where(e => e.course_id == course.id); if (tempCS.ToList().Count > 0) { foreach (var item in tempCS) { item.is_deleted = true; } } } else { // set this course-exam is_deleted = false var tempCE = db.course_exam.Where(e => e.course_id == course.id); if (tempCE.ToList().Count > 0) { foreach (var item in tempCE) { item.is_deleted = false; } } // set this course - section is_deleted = false var tempCS = db.sections.Where(e => e.course_id == course.id); if (tempCS.ToList().Count > 0) { foreach (var item in tempCS) { item.is_deleted = false; } } } course.modified_on = DateTime.Now.AddHours(1); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.required_room_type_id = new SelectList(db.room_type.Where(c => c.is_deleted == false), "id", "type", db.course_exam.Where(w => w.course_id == course.id).First().required_room_type_id); ViewBag.course_id = new SelectList(db.courses.Where(p => !(db.course_exam.Any(p2 => p2.course_id == p.id)) && p.is_deleted == false).OrderBy(o => o.code), "id", "courseDropdown", course.id); ViewBag.faculty_id = new SelectList(db.faculties.Where(c => c.is_deleted == false).OrderBy(o => o.first_name), "id", "fullName", db.sections.Where(s => s.course_id == course.id && s.section_number == 1).First().faculty.id); ViewBag.program_id = new SelectList(db.programs.Where(c => c.is_deleted == false), "id", "title", db.sections.Where(s => s.course_id == course.id && s.section_number == 1).First().program.id); ViewBag.room_id = new SelectList(db.rooms.Where(p => p.is_deleted == false).OrderBy(o => o.name), "id", "name", db.sections.Where(s => s.course_id == course.id && s.section_number == 1).First().room.id); var weekDays = Enum.GetValues(typeof(DayOfWeek)).Cast <DayOfWeek>() .Select(dow => new { Value = (int)dow - 1, Text = dow.ToString() }) .ToList(); ViewBag.class_weekday = new SelectList(weekDays, "Value", "Text", db.sections.Where(s => s.course_id == course.id && s.section_number == 1).First().class_weekday); ViewBag.class_start_time = db.sections.Where(s => s.course_id == course.id && s.section_number == 1).First().class_start_time; ViewBag.exam_length = db.course_exam.Where(w => w.course_id == course.id).First().exam_length; ViewBag.note = db.course_exam.Where(w => w.course_id == course.id).First().final_exam_note; ViewBag.has_exam = db.course_exam.Where(w => w.course_id == course.id).First().have_final_exam; return(View(course)); }
public ActionResult EditExam(course crs) { if (ModelState.IsValid) { //======first check========== DateTime ExamA = crs.ExamA; DateTime ExamB = crs.ExamB; int value = DateTime.Compare(ExamA, ExamB); //======second check========= int fa = 0, fb = 0; var lec = DB.users.FirstOrDefault(s => s.ID.Equals(crs.LecturerID)); List <DateTime> exama = new List <DateTime>(); List <DateTime> examb = new List <DateTime>(); foreach (course c in DB.courses) { if (crs.LecturerID.Equals(c.LecturerID)) { if (!crs.ID.Equals(c.ID)) { exama.Add(c.ExamA); examb.Add(c.ExamB); } } } foreach (DateTime a in exama) { if (a == ExamA || a == ExamB) { fa = 1; } } foreach (DateTime b in examb) { if (b == ExamB || b == ExamA) { fb = 1; } } if (fa == 0) { if (fb == 0) { if (value < 0) { try { var cors = DB.courses.FirstOrDefault(s => s.ID.Equals(crs.ID)); cors.ID = crs.ID; cors.Name = crs.Name; cors.Points = crs.Points; cors.LecturerID = crs.LecturerID; cors.ExamA = crs.ExamA; cors.ExamB = crs.ExamB; cors.startlec = crs.startlec; cors.endlec = crs.endlec; cors.Day = crs.Day; cors.ClassRoom = crs.ClassRoom; DB.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { } // DB.Entry(crs).State = EntityState.Modified; } else { ModelState.AddModelError("ExamA", "Moed A must be earlier than Moed B"); } } else { ModelState.AddModelError("ExamB", "the lecturer have an onther exam in this date"); } } else { ModelState.AddModelError("ExamA", "the lecturer have an onther exam in this date"); } } return(View(crs)); }
public ActionResult Submit(course course) { if (ModelState.IsValid) { if (course != null) { int flag = 0, classroomflag = 0; var cors = DB.courses.FirstOrDefault(s => s.ID.Equals(course.ID)); //===================ckeck if this course conflict with other courses to the lecturer==========// int start, end, cstart, cend; int flag2 = 0; cstart = Int32.Parse(course.startlec.Substring(0, 2)); cend = Int32.Parse(course.endlec.Substring(0, 2)); foreach (course c in DB.courses) { if (course.LecturerID.Equals(c.LecturerID)) { if (!course.ID.Equals(c.ID)) { if (c.Day.Equals(course.Day)) { start = Int32.Parse(c.startlec.Substring(0, 2)); end = Int32.Parse(c.endlec.Substring(0, 2)); if (c.startlec.Equals(course.startlec) || (start >= cstart && start < cend) || (end > cstart && end <= cend)) { flag2 = 1; } } } } } foreach (course c in DB.courses) { if (course.ID.Equals(c.ID)) { if (c.Day.Equals(course.Day)) { start = Int32.Parse(c.startlec.Substring(0, 2)); end = Int32.Parse(c.endlec.Substring(0, 2)); if (c.startlec.Equals(course.startlec) || (start >= cstart && start < cend) || (end > cstart && end <= cend)) { if (course.ClassRoom.Equals(c.ClassRoom)) { classroomflag = 1; } } } } } //======first check========== DateTime ExamA = course.ExamA; DateTime ExamB = course.ExamB; int value = DateTime.Compare(ExamA, ExamB); //======second check========= int fa = 0, fb = 0; var lec = DB.users.FirstOrDefault(s => s.ID.Equals(course.LecturerID)); List <DateTime> exama = new List <DateTime>(); List <DateTime> examb = new List <DateTime>(); foreach (course c in DB.courses) { if (course.LecturerID.Equals(c.LecturerID)) { if (!course.ID.Equals(c.ID)) { exama.Add(c.ExamA); examb.Add(c.ExamB); } } } foreach (DateTime a in exama) { if (a == ExamA || a == ExamB) { fa = 1; } } foreach (DateTime b in examb) { if (b == ExamB || b == ExamA) { fb = 1; } } //=============================================================================================// foreach (user u in DB.users) { if (course.LecturerID.Equals(u.ID) && u.UserTyper == 1) { flag = 1; } } if (fa == 0) { if (fb == 0) { if (value > 0) { if (cors == null) { if (flag == 1) { if (flag2 == 0) { if (classroomflag == 0) { DB.courses.Add(course); DB.SaveChanges(); return(RedirectToAction("Index")); } else { ModelState.AddModelError("ClassRoom", "There are another lecture in this Class"); } } else { ModelState.AddModelError("LecturerID", "The Lecturer have onther course in this time,Please change lecturer or time"); } } else { ModelState.AddModelError("LecturerID", "The Lecturer does not exsit!"); } } else { ModelState.AddModelError("ID", "The Course Already exsit!"); } } else { ModelState.AddModelError("ExamA", "Moed A must be earlier than Moed B"); } } else { ModelState.AddModelError("ExamB", "the lecturer have an onther exam in this date"); } } else { ModelState.AddModelError("ExamA", "the lecturer have an onther exam in this date"); } } } return(View("AddCourse", course)); }
public void add(course entity) { crs.Insert(entity.Name, entity.Duration, entity.Fees, entity.Eligibility, entity.Totalseat); }
public void Addcourse(course course) { courseDao.Addcourse(course); }
public JsonResult CreateCourse(int crsuniq, int funiq, int schuniq) { course sisCourse = SISdb.courses.Find(crsuniq); school sisSchool = SISdb.schools.Find(schuniq); facdemo courseTeacher = SISdb.facdemoes.Find(funiq); int schoolYear = Convert.ToInt32(SISdb.schools.Max(s => s.schyear)); string sisCourseId = schoolYear + ":" + crsuniq + ":" + funiq; //get the account id int accountId; AccountIDs.TryGetValue(sisSchool.schoolc, out accountId); //make sure the course doesn't exist CanvasCourseModel vCourse = GetCourse(crsuniq, funiq, schuniq); if (vCourse != null) { //the course exists return the id return(Json(new { success = "true", courseId = vCourse.id })); } CanvasCourseModel vSisCourse = GetCourseBySISId(sisCourseId); if (vSisCourse != null) { //the course exists return the id return(Json(new { success = "true", courseId = vSisCourse.id })); } string courseJson = "{ \"account_id\": \"" + accountId + "\"," + "\"course\": {" + "\"name\": \"" + sisCourse.descript + " : " + courseTeacher.lastname.Trim() + " " + courseTeacher.firstname.Trim() + "\"," + "\"course_code\": \"" + sisCourse.descript + " : " + courseTeacher.lastname.Trim() + " " + courseTeacher.firstname.Trim() + "\"," + "\"sis_course_id\": \"" + sisCourseId + "\"}}"; //send the data string createCourseURL = CanvasUrl + "accounts/" + accountId + "/courses?access_token=" + OAuthKey; var httpWebRequest = (HttpWebRequest)WebRequest.Create(createCourseURL); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; CanvasCourseModel newCourse = new CanvasCourseModel(); using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { streamWriter.Write(courseJson); streamWriter.Flush(); streamWriter.Close(); var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var serializer = new JsonSerializer(); using (var jsonTextReader = new JsonTextReader(streamReader)) { newCourse = serializer.Deserialize <CanvasCourseModel>(jsonTextReader); } } } //attach the teacher AssignTeacherToCourse(funiq, newCourse.id, schuniq); return(Json(new { success = "true", courseId = newCourse.id })); }
public async Task <course> GetByKeyAsync(int id) { course course = await db.courses.FindAsync(id); return(course); }
public void parse_all(string text) { skobochki temp0; temp0.pos = 0; temp0.frag = ""; for (int i = 0; i < text.Length; i++) { if (text[i] == '{') { a.Add(temp0); temp0.pos++; temp0.frag = ""; i++; } if (text[i] == '}') { a.Add(temp0); temp0.pos--; temp0.frag = ""; i++; } temp0.frag += text[i]; } /* * for (int i = 0; i < a.Count; i++) * { * richTextBox1.Text += "---->" + a[i].frag + "<---- " + Convert.ToString(a[i].pos) + "\n"; * }*/ for (int i = 0; i < a.Count; i++) { if (a[i].pos == 0) { course temp1 = new course(); c.Add(temp1); } if (i > 0) { if (a[i - 1].pos == 1) { if (a[i].pos == 2) { if (a[i - 1].frag.LastIndexOf("Имя") != -1) { if (a[i - 1].frag.Substring(a[i - 1].frag.LastIndexOf("Имя")).Equals("Имя")) { c.Last().name = a[i].frag; } } } } if (a[i - 1].pos == 2) { if (a[i].pos == 3) { if (a[i - 1].frag.LastIndexOf("Имя") != -1) { if (a[i - 1].frag.Substring(a[i - 1].frag.LastIndexOf("Имя")).Equals("Имя")) { course.page temp1 = new course.page(); temp1.name = a[i].frag; c.Last().p.Add(temp1); } } if (a[i - 1].frag.LastIndexOf("Текст") != -1) { if (a[i - 1].frag.Substring(a[i - 1].frag.LastIndexOf("Текст")).Equals("Текст")) { c.Last().p.Last().text = a[i].frag; } } if (a[i - 1].frag.LastIndexOf("Картинки") != -1) { if (a[i - 1].frag.Substring(a[i - 1].frag.LastIndexOf("Картинки")).Equals("Картинки")) { c.Last().p.Last().picture = a[i].frag; } } if (a[i - 1].frag.LastIndexOf("Ответы") != -1) { if (a[i - 1].frag.Substring(a[i - 1].frag.LastIndexOf("Ответы")).Equals("Ответы")) { c.Last().p.Last().answer = a[i].frag; } } } } } } /* * for (int i = 0; i < c.Count; i++) * { * richTextBox1.Text += c[i].name; * for (int j = 0; j < c[i].p.Count; j++) * { * richTextBox1.Text += c[i].p[j].name; * richTextBox1.Text += c[i].p[j].text; * richTextBox1.Text += c[i].p[j].picture; * richTextBox1.Text += c[i].p[j].answer; * } * } */ analyze(); }
//插入数据 public int Add(course c) { return(cdal.Add(c)); }
public ActionResult Submit(grade model) { if (ModelState.IsValid) { course temp1 = null; course temp2 = null; int flag = 0; List <course> courss = new List <course>(); List <string> user_courses = new List <string>(); string studentid = model.StudentID; string courseid = model.CourseID; foreach (grade g in DB.grades) { if (g.StudentID.Equals(studentid)) { user_courses.Add(g.CourseID); } } foreach (string s in user_courses) { temp1 = DB.courses.Find(s); temp2 = DB.courses.Find(courseid); if (temp1 != null && temp2 != null) { if (temp1.Day.Equals(temp2.Day) && temp1.startlec.Equals(temp2.startlec) && temp1 != temp2) { flag = 1; } } } var crs = DB.courses.FirstOrDefault(s => s.ID.Equals(model.CourseID)); var std = DB.users.FirstOrDefault(s => s.ID.Equals(model.StudentID)); var grad = DB.grades.FirstOrDefault(s => s.CourseID.Equals(model.CourseID) && s.StudentID.Equals(model.StudentID)); if (crs != null && std != null) { if (grad == null) { if (flag == 0) { if (std.UserTyper == 0) { DB.grades.Add(model); DB.SaveChanges(); return(RedirectToAction("AddCourseToStudent")); } else { ModelState.AddModelError("StudentID", "student id is incorrect"); } } else { ModelState.AddModelError("CourseID", "There are conflict with onther course at the same time"); } } else { ModelState.AddModelError("CourseID", "Already having this Course"); } } else { ModelState.AddModelError("StudentID", "The student id is incorrect"); ModelState.AddModelError("CourseID", "The course id is incorrect"); } } else { ModelState.AddModelError("StudentID", "The course id or student id is incorrect"); } return(View("AddCourseToStudent", model)); }
//更新数据 public int Update(course c) { return(cdal.Update(c)); }
public IHttpActionResult Postcourse([FromBody] course course) { string imageName = course.image_course; var httpRequest = HttpContext.Current.Request; var postFile = httpRequest.Files[0]; imageName = new String(Path.GetFileNameWithoutExtension(postFile.FileName).Take(10).ToArray()).Replace(" ", "-"); imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postFile.FileName); var filePath = HttpContext.Current.Server.MapPath("~/Images/" + imageName); //var filePath = "~/assets/image/" + imageName; postFile.SaveAs(filePath); //string imageName = null ; //var httpRequest = HttpContext.Current.Request; //var postFile = httpRequest.Files[0]; //imageName = new String(Path.GetFileNameWithoutExtension(postFile.FileName).Take(10).ToArray()).Replace(" ", "-"); //imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postFile.FileName); //var filePath = HttpContext.Current.Server.MapPath("~/Images/" + imageName); //postFile.SaveAs(filePath); Guid originalGuid = Guid.NewGuid(); string guild = originalGuid.ToString("D"); Guid newGuid = Guid.Parse(guild); var result = from a in db.courses join b in db.skills on a.idskill equals b.idskill join c in db.trainees on a.trainee_course equals c.traineeid join d in db.categories on b.categoryid equals d.categoryid where b.idskill == a.idskill && c.traineeid == a.trainee_course select a; foreach (var item in result) { if (item.idskill == course.idskill) { return(BadRequest()); } } db.courses.Add(new course { courseid = newGuid.ToString(), title = course.title, description = course.description, city = course.city, address = course.address, time = course.time, createddate = DateTime.UtcNow.Date, status = 0, idskill = course.idskill, trainee_course = course.trainee_course, isnotification = 1, image_course = imageName, }); db.SaveChanges(); var v = (from a in db.courses join b in db.skills on a.idskill equals b.idskill join c in db.categories on b.categoryid equals c.categoryid join d in db.mentors on b.idskill equals d.idskill join e in db.trainees on a.trainee_course equals e.traineeid where b.idskill == d.idskill && a.idskill == a.idskill select new { a.isnotification, d.isreceivenotification, d.email, titlecourse = a.title, addresscourse = a.address, citycourse = a.city, timecourse = a.time, b.idskill, d.name, b.skillname, nametrainee = e.name, emailtrainee = e.email, phonetrainee = e.phone }).ToList(); foreach (var item in v) { if (item.idskill == course.idskill && item.isnotification == item.isreceivenotification) { SmtpClient client = new SmtpClient(); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; client.Host = "smtp.gmail.com"; client.Port = 587; // setup Smtp authentication System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("*****@*****.**", "0966117765qwer"); client.UseDefaultCredentials = false; client.Credentials = credentials; //can be obtained from your model MailMessage msg = new MailMessage(); msg.From = new MailAddress("*****@*****.**"); msg.To.Add(new MailAddress(item.email)); // Truyền người nhận msg.Subject = "[" + item.nametrainee + "] - Tôi đang quan tâm đến khóa học - " + item.skillname; // Tiêu đề msg.IsBodyHtml = true; msg.Body = string.Format("<html><head></head><body><b>Xin Chào " + item.name + ".<br/>" + "Đây là thông tin khóa học:<br/> - Tên khóa học: " + "<h2 style=" + "color:red" + ">" + item.titlecourse + "</h2>" + "<br/>- Địa chỉ: " + "<b style=" + "color:blue" + ">" + item.addresscourse + "," + item.citycourse + "</b>" + "<br/>- Thời gian học: " + "<mark>" + item.timecourse + "</mark>" + "<br/>Nếu thích hợp với khóa học thì bạn vui lòng liên hệ với tôi qua email: " + "<mark>" + item.emailtrainee + "</mark>" + "<br /> Hoặc Số điện thoại: " + "<a href=" + "tel:" + item.phonetrainee + " >" + "<mark>" + item.phonetrainee + "</mark>" + "</a>" + "(Nhấn để gọi trực tiếp)" + "</b></body>");// Nội dung mail client.Send(msg); } } return(CreatedAtRoute("Postcourse", new { id = course.courseid }, course)); }
public void AddCourse(course, Course) { course = Course; }
static void Main(string[] args) { // 5.Run the same code in Program.cs from Module 5 to create instances of your classes so that you can setup a single course that is part of a program and a degree path. Be sure to include at least one Teacher and an array of Students. student student1 = new student(); student1.Firstname = "Tony"; student1.Lastname = "Stark"; student1.Dateofbirth = "1st Jan 1969"; student1.Grades.Push(90); student1.Grades.Push(100); student1.Grades.Push(90); student1.Grades.Push(75); student1.Grades.Push(60); student student2 = new student(); student2.Firstname = "Steve"; student2.Lastname = "Rodgers"; student2.Dateofbirth = "1st Feb 1920"; student2.Grades.Push(90); student2.Grades.Push(100); student2.Grades.Push(90); student2.Grades.Push(75); student2.Grades.Push(60); student student3 = new student(); student3.Firstname = "Bruce"; student3.Lastname = "Banner"; student3.Dateofbirth = "1st April 1975"; student3.Grades.Push(90); student3.Grades.Push(100); student3.Grades.Push(90); student3.Grades.Push(75); student3.Grades.Push(60); //2.Instantiate a Course object called Programming with C#. course ProgrammingCourses = new course(); ProgrammingCourses.CourseTitle = "Programming with C#"; ProgrammingCourses.CourseLength = 3; ProgrammingCourses.CourseCredits = 90; //3.Add your three students to this Course object ProgrammingCourses.students.Add(student1); ProgrammingCourses.students.Add(student2); ProgrammingCourses.students.Add(student3); //4.Instantiate at least one Teacher object. teacher teacher1 = new teacher(); teacher1.Firstname = "Stan"; teacher1.Lastname = "Winston"; teacher1.Dateofbirth = "1st Dec 1919"; //5.Add that Teacher object to your Course object ProgrammingCourses.teachers[0] = teacher1; //6.Instantiate a Degree object, such as Bachelor. degree degree1 = new degree(); degree1.DegreeName = "Bachelor"; //7.Add your Course object to the Degree object. degree1.degreecourse = ProgrammingCourses; //8.Instantiate a UProgram object called Information Technology. uprogram uprogram1 = new uprogram(); uprogram1.Programtitle = "Information Technology"; //9.Add the Degree object to the UProgram object. uprogram1.Programdegree = degree1; //10.Using Console.WriteLine statements, output //Console.WriteLine("The {0} program contains the {1} degree", uprogram1.Programtitle, degree1.DegreeName); //Console.WriteLine("The {0} degree contains the course {1}", degree1.DegreeName, ProgrammingCourses.CourseTitle); //Console.WriteLine("The {0} course contains {1} students(s)", ProgrammingCourses.CourseTitle, ProgrammingCourses.CourseTitle); ProgrammingCourses.ListStudents(); }
private void CheckcourseIsNotNullThrowException(course course) { throw new NotImplementedException(); }
public IActionResult DeleteById([FromBody] course cr) { cr.Name = "这是Delete"; return(Json(cr)); }
private void AddCourses() { System.IO.StreamReader inFile = new System.IO.StreamReader(textBox1.Text); int lineNum = 0; int numInserted = 0; int tbsInserted = 0; string inLine; Regex reg = new Regex(@"[SF]\d{2}\ [A-Z]{2,3}\-\d{3}\-\d{2}\ {1,2}[a-zA-z ]{15}\ [a-zA-z ]{10}\ \d\.\d{2}\ \d{1,3}\ {1,3}\d(\ \d{5})+"); bool keepGoing = true; while (!inFile.EndOfStream && keepGoing) { inLine = inFile.ReadLine(); lineNum++; if (!reg.IsMatch(inLine)) { DialogResult result = MessageBox.Show("Error - inproper input format on line " + lineNum.ToString() + ". Continue?", "Error", MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.No) { keepGoing = false; } } else { linqtoregdbDataContext db = new linqtoregdbDataContext(); string semesterIn, courseNameIn, courseTitleIn, instructor; decimal courseCreditIn; int numSeatsIn, numTBs; List <int> timeBlocksIn = new List <int>(); semesterIn = inLine.Substring(0, 3); courseNameIn = TrimSpaces(inLine.Substring(4, 10)); courseTitleIn = TrimSpaces(inLine.Substring(15, 15)); instructor = TrimSpaces(inLine.Substring(31, 10)); courseCreditIn = Convert.ToDecimal(inLine.Substring(42, 4)); numSeatsIn = Convert.ToInt32(TrimSpaces(inLine.Substring(47, 3))); numTBs = (int)char.GetNumericValue(inLine[51]); for (int i = 0; i < numTBs; i++) { timeBlocksIn.Add(Convert.ToInt32(inLine.Substring(53 + i * 6, 5))); } var queryGetInstructorID = (from usr in db.users where usr.username == instructor select usr.userID).FirstOrDefault(); course newCourse = new course { semester = semesterIn, courseName = courseNameIn, courseTitle = courseTitleIn, instructor = queryGetInstructorID, courseCredit = courseCreditIn, numSeats = numSeatsIn }; try { db.courses.InsertOnSubmit(newCourse); db.SubmitChanges(); var queryGetCourseID = (from crs in db.courses where crs.courseName == courseNameIn select crs.courseID).FirstOrDefault(); foreach (var c in timeBlocksIn) { course_timeblock newCourseTimeblock = new course_timeblock { courseID = queryGetCourseID, timeblock = c }; db.course_timeblocks.InsertOnSubmit(newCourseTimeblock); tbsInserted++; } db.SubmitChanges(); numInserted++; } catch (Exception) { DialogResult result = MessageBox.Show("Error - invalid course insertion attempted. Skip user and continue?", "Error", MessageBoxButtons.YesNo); if (result == System.Windows.Forms.DialogResult.No) { keepGoing = false; } } } } MessageBox.Show(numInserted.ToString() + " courses with " + tbsInserted.ToString() + " total timeblocks inserted successfully."); inFile.Close(); }
// PUT: api/Courses/5 public bool Put(course crs) { return(unitOfWork.CourseManager.UpdateEntity(crs)); }
public ActionResult Add() { course un = new course(); return(View(un)); }