public async Task <IHttpActionResult> PostTeach(Teach teach) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Teaches.Add(teach); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (TeachExists(teach.TeacherId)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = teach.TeacherId }, teach)); }
public async Task <IHttpActionResult> PutTeach(int id, Teach teach) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != teach.TeacherId) { return(BadRequest()); } db.Entry(teach).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeachExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> PostCourse() { Course course = new Course(); string pathImage; var httpRequest = HttpContext.Current.Request; //Upload Image var postedFile = httpRequest.Files["Image"]; course.Code = httpRequest["Code"]; course.Name = httpRequest["Name"]; course.Description = httpRequest["Description"]; course.MaxDegree = int.Parse(httpRequest["MaxDegree"]); course.MinDegree = int.Parse(httpRequest["MinDegree"]); course.StageID = int.Parse(httpRequest["StageID"]); // semester sem = (semester)Enum.Parse(typeof(semester), httpRequest["Semester"]); course.Semester = httpRequest["Semester"]; //course.Semester = sem; //Custom filename pathImage = new String(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()).Replace(" ", "-"); pathImage += DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName); string filePath = ""; filePath = HttpContext.Current.Server.MapPath("~/Content/Images/" + pathImage); pathImage = "http://localhost:51851/Content/Images/" + pathImage; course.Image = pathImage; postedFile.SaveAs(filePath); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { db.Courses.Add(course); db.SaveChanges(); Teach teach = new Teach(); teach.CourseId = course.Id; teach.TeacherID = httpRequest["TeacherID"]; db.Teach.Add(teach); db.SaveChanges(); } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok(course));//CreatedAtRoute("DefaultApi", new { id = course.Code }, course); }
private void LoadEntity(DataRow dataRow, Teach teach) { teach.Tea_id = Convert.ToString(dataRow["tea_id"]); //判断是否为空 teach.Cou_id = dataRow["cou_id"] != DBNull.Value ? dataRow["cou_id"].ToString() : string.Empty; teach.Cou_num = dataRow["cou_num"] != DBNull.Value ? dataRow["cou_num"].ToString() : string.Empty; teach.Stu_id = dataRow["stu_id"] != DBNull.Value ? dataRow["stu_id"].ToString() : string.Empty; teach.Stu_name = dataRow["stu_name"] != DBNull.Value ? dataRow["stu_name"].ToString() : string.Empty; }
public async Task <IHttpActionResult> GetTeach(int id) { Teach teach = await db.Teaches.FindAsync(id); if (teach == null) { return(NotFound()); } return(Ok(teach)); }
private void Start() { aspectRatio = GetComponent <AspectRatio>(); teach = GetComponent <Teach>(); menu = GetComponent <Menu>(); scr = new Vector2(1080f, 1080f / aspectRatio.cam.aspect); trStart = startCut.GetComponent <RectTransform>(); trEnd = endCut.GetComponent <RectTransform>(); lr = lineCut.GetComponent <LineRenderer>(); count = 0; StartCoroutine(RemovingActivity()); Started(); }
public MarkDTOOut CreateMarkAdmin(string userId, MarkDTOIn newMark) { logger.Info($"Getting student {newMark.StudentID} over student service, from Create mark teacher, mark service"); Student student = studentsService.GetStudent(newMark.StudentID); logger.Info($"Getting subject {newMark.SubjectID} over subject service, from create mark teacher, mark service"); Subject subject = subjectsService.GetSubjectByID(newMark.SubjectID); logger.Info($"Getting teach for student {student.UserName}, subject {subject.SubjectName} and teacher with Id {userId}"); Teach teach = subject.Teaches.Where(x => x.StudentDepartments.Id == student.StudentDepartments.Id && x.Teachers.Id == newMark.TeacherID && x.Subject.Id == subject.Id).FirstOrDefault(); if (teach == null) { logger.Info($"Teacher with id {userId} tried to enter the mark to wrong student or subject"); throw new TeacherDontTeachThisSubjectException("Wrong teacher or subject"); } if (newMark.MarkValue < 1 || newMark.MarkValue > 5) { logger.Info($"Teacher with id {userId} tried to enter the mark out of boundaries"); throw new BadRequestException("Mark van be only 1,2,3,4,5"); } logger.Info("Preparing mark for storing in db"); Mark mark = new Mark() { MarkValue = newMark.MarkValue, Teaches = teach }; logger.Info($"Storing mark {mark.Id} in mark repo"); db.MarksRepository.Insert(mark); logger.Info($"Saving marl with id {mark.Id} in db"); db.Save(); logger.Info($"Converting mark with id {mark.Id} to DTO"); MarkDTOOut markDTO = new MarkDTOOut() { Mark = new MarkDTODate() { Id = mark.Id, MarkValue = mark.MarkValue, InsertDate = mark.InsertDate }, Student = Utilities.ConverterDTO.SimpleDTOConverter <StudentDTO>(mark.Teaches.StudentDepartments.Students), Subject = Utilities.ConverterDTO.SimpleDTOConverter <SubjectDTO>(mark.Teaches.Subject), Teacher = Utilities.ConverterDTO.SimpleDTOConverter <TeacherDTO>(mark.Teaches.Teachers) }; return(markDTO); }
public async Task <IHttpActionResult> DeleteTeach(int id) { Teach teach = await db.Teaches.FindAsync(id); if (teach == null) { return(NotFound()); } db.Teaches.Remove(teach); await db.SaveChangesAsync(); return(Ok(teach)); }
public void Index(Teach teach) { scheduleContext.Teaches.Add(teach); scheduleContext.SaveChanges(); Response.Redirect(Request.Url.ToString()); }
public Teacher(Name firstName, Name lastName) { FirstName = firstName; LastName = lastName; TeachAction = new Teach(); }
public MarkDTOOut CreateMarkTeacher(string userId, MarkDTOIn newMark) { logger.Info($"Getting student {newMark.StudentID} over student service, from Create mark teacher, mark service"); Student student = studentsService.GetStudent(newMark.StudentID); logger.Info($"Getting subject {newMark.SubjectID} over subject service, from create mark teacher, mark service"); Subject subject = subjectsService.GetSubjectByID(newMark.SubjectID); logger.Info($"Getting teach for student {student.UserName}, subject {subject.SubjectName} and teacher with Id {userId}"); Teach teach = subject.Teaches.Where(x => x.StudentDepartments.Id == student.StudentDepartments.Id && x.Teachers.Id == userId && x.Subject.Id == subject.Id).FirstOrDefault(); if (teach == null) { logger.Info($"Teacher with id {userId} tried to enter the mark to wrong student or subject"); throw new TeacherDontTeachThisSubjectException("Wrong student or subject"); } if (newMark.MarkValue < 1 || newMark.MarkValue > 5) { logger.Info($"Teacher with id {userId} tried to enter the mark out of boundaries"); throw new BadRequestException("Mark van be only 1,2,3,4,5"); } logger.Info("Preparing mark for storing in db"); Mark mark = new Mark() { MarkValue = newMark.MarkValue, Teaches = teach }; logger.Info($"Storing mark {mark.Id} in mark repo"); db.MarksRepository.Insert(mark); logger.Info($"Saving marl with id {mark.Id} in db"); db.Save(); logger.Info($"Preparing student's {student.UserName} parent's for mail sending"); IEnumerable <ParentDTOOut> parents = mark.Teaches.StudentDepartments.Students.Parents.Select(x => new ParentDTOOut() { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, Email = x.Email, UserName = x.UserName }); logger.Info($"Converting mark with id {mark.Id} to DTO"); MarkDTOOut markDTO = new MarkDTOOut() { Mark = new MarkDTODate() { Id = mark.Id, MarkValue = mark.MarkValue, InsertDate = mark.InsertDate }, Student = Utilities.ConverterDTO.SimpleDTOConverter <StudentDTO>(mark.Teaches.StudentDepartments.Students), Subject = Utilities.ConverterDTO.SimpleDTOConverter <SubjectDTO>(mark.Teaches.Subject), Teacher = Utilities.ConverterDTO.SimpleDTOConverter <TeacherDTO>(mark.Teaches.Teachers) }; foreach (var parent in parents) { try { logger.Info($"Sending parent {parent.UserName} to mail service"); emailService.SendEmail(parent, markDTO); } catch (Exception) { logger.Info($"Something went wrong with email sending to {parent.Email}"); continue; } } return(markDTO); }
public TeachDTOOut CreateTeach(TeachDTOIn newTeach) { logger.Info("Get student department over student department service, create teach teaches service"); StudentDepartment studentDepartment = studentDepartmentsService.GetStudentDepartmentByID(newTeach.StudentDepartmentID); logger.Info("Get teacher over teacher service, create teach teaches service"); Teacher teacher = teachersService.GetById(newTeach.TeacherID); logger.Info("Get subject over subject service, create teach teaches service"); Subject subject = subjectsService.GetSubjectByID(newTeach.SubjectID); logger.Info("Get teaches over teach service, create teach teaches service"); IEnumerable <Teach> teach = GetAllTeach(); //Check if subject is for students grade logger.Info("Checking if subject is for the selected grade, create teaches, teaches service"); var isGradeOk = subject.Grades.Any(x => x.Id == studentDepartment.Departments.Grades.Id); if (!isGradeOk) { throw new SubjectIsNotForThisGrade("Wrong subject"); } //check if teacher is teaching this subject logger.Info("Checking if teacher is teaching subject"); var result = teacher.Subjects.Contains(subject); if (!result) { logger.Info("Throwing exception, wrong teacher subject pair"); throw new TeacherDontTeachThisSubjectException("Teacher - subject pair does not match"); } //check if subject is alreaady added to student logger.Info("Checking if subject is already added to student"); var subjectExists = teach.Any(x => x.Subject.Equals(subject) && x.StudentDepartments.Equals(studentDepartment)); if (subjectExists) { logger.Info("Throwing exception subject already added to student"); throw new SubjectExistsException($"Subject {subject.SubjectName} already added to student {studentDepartment.Students.UserName}"); } //check if teacher teach to this department, and finds who teach logger.Info("Checking if theacher is teach in department"); var isDepartmentOK = teach.Any(x => x.Subject.Equals(subject) && x.Teachers.Equals(teacher) && x.StudentDepartments.Departments.Id.Equals(studentDepartment.Departments.Id)); var isSubjectInDepartment = teach.Any(x => x.Subject.Equals(subject) && x.StudentDepartments.Departments.Id.Equals(studentDepartment.Departments.Id)); var whoTeach = teach.Where(x => x.Subject.Equals(subject) && x.StudentDepartments.Equals(studentDepartment)).Select(x => x.Teachers.UserName); if (!isDepartmentOK) { if (isSubjectInDepartment) { logger.Info("Throwing exception teacher doesn't teach in department"); throw new TeacherDontTeachThisDepartment($"Teacher {teacher.UserName} doesn't teach to department {studentDepartment.Departments.DepartmentName}, {whoTeach} does."); } } logger.Info("Preparing teach for save in db"); Teach teachIn = new Teach() { StudentDepartments = studentDepartment, Teachers = teacher, Subject = subject }; logger.Info("Access to teaches repository for insert new teach"); db.TeachesRepository.Insert(teachIn); logger.Info("db save new teach"); db.Save(); logger.Info("Converting to dto for output"); TeachDTOOut teachDTOOut = new TeachDTOOut() { Id = teachIn.Id, Student = Utilities.ConverterDTO.SimpleDTOConverter <StudentDTO>(teachIn.StudentDepartments.Students), Department = Utilities.ConverterDTO.SimpleDTOConverter <DepartmentDTOStudent>(teachIn.StudentDepartments.Departments), TeacherSubject = studentDepartment.Teaches.Select(x => new TeacherSubjectDTO() { Teacher = Utilities.ConverterDTO.SimpleDTOConverter <TeacherDTO>(x.Teachers), Subject = Utilities.ConverterDTO.SimpleDTOConverter <SubjectDTO>(x.Subject) }) }; return(teachDTOOut); }