public InternshipCourseEntity(InternshipCourse internshipCourse, params object[] args) { this.Id = internshipCourse.Id; this.StudentId = internshipCourse.StudentId; this.CompanyId = internshipCourse.CompanyId; this.LecturerId = internshipCourse.LecturerId; this.Start = internshipCourse.Start; this.End = internshipCourse.End; this.File = internshipCourse.File; this.LecturerComment = internshipCourse.LecturerComment; this.CompanyComment = internshipCourse.CompanyComment; this.FinalScore = internshipCourse.FinalScore; foreach (var arg in args) { if (arg is Company) { this.CompanyEntity = internshipCourse.Company == null ? null : new CompanyEntity(arg as Company); } if (arg is Student) { this.StudentEntity = internshipCourse.Student == null ? null : new StudentEntity(arg as Student); } if (arg is ICollection <InternReport> ) { this.InternReportEntities = (arg as ICollection <InternReport>).Select(ir => new InternReportEntity(ir)).ToList(); } } }
public ActionResult Edit(int?id) { InternshipCourse internshipCourse = db.InternshipCourses.Find(id); InternshipCourseViewModel model = Mapper.Map <InternshipCourse, InternshipCourseViewModel>(internshipCourse); return(View(model)); }
public ActionResult DeleteConfirmed(int id) { InternshipCourse internshipCourse = db.InternshipCourses.Find(id); db.InternshipCourses.Remove(internshipCourse); db.SaveChanges(); return(RedirectToAction("Index")); }
//Get using StudentId, Student use public InternshipCourseEntity GetByStudentId(UserEntity userEntity, Guid StudentId) { InternshipCourse InternshipCourse = IMSContext.InternshipCourses.Where(s => s.StudentId.Equals(StudentId)).FirstOrDefault(); if (InternshipCourse == null) { throw new BadRequestException("Khong tim thay course"); } return(new InternshipCourseEntity(InternshipCourse)); }
public ActionResult Edit(InternshipCourseViewModel model) { if (ModelState.IsValid) { InternshipCourse internshipCourse = Mapper.Map <InternshipCourseViewModel, InternshipCourse>(model); db.Entry(internshipCourse).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Create(InternshipCourseViewModel model) { if (ModelState.IsValid) { InternshipCourse internshipCourse = Mapper.Map <InternshipCourseViewModel, InternshipCourse>(model); db.InternshipCourses.Add(internshipCourse); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public InternshipCourseEntity Update(UserEntity userEntity, Guid internshipCourseId, InternshipCourseEntity internshipCourseEntity) { Student student = IMSContext.Students.Where(s => s.Id == userEntity.Id).FirstOrDefault(); InternshipCourse internshipCourse = IMSContext.InternshipCourses.Where(s => s.Id == internshipCourseId).FirstOrDefault(); if (internshipCourse == null) { throw new BadRequestException("Khong tim thay course"); } internshipCourseEntity.ToModel(internshipCourse); IMSContext.SaveChanges(); return(new InternshipCourseEntity(internshipCourse)); }
public InternshipCourseEntity Create(UserEntity userEntity, InternshipCourseEntity internshipCourseEntity) { InternshipCourse internshipCourse = internshipCourseEntity.ToModel(); Student student = IMSContext.Students.Where(s => s.Id == userEntity.Id).FirstOrDefault(); if (student == null) { throw new BadRequestException("user khong tim thay"); } student.InternshipCourses.Add(internshipCourse); IMSContext.InternshipCourses.Add(internshipCourse); IMSContext.SaveChanges(); return(new InternshipCourseEntity(internshipCourse)); }
public bool Delete(UserEntity userEntity, Guid internshipCourseId) { InternshipCourse internshipCourse = IMSContext.InternshipCourses.Where(s => s.Id == internshipCourseId).FirstOrDefault(); if (internshipCourse == null) { return(false); } Student student = IMSContext.Students.Where(s => s.Id == userEntity.Id).FirstOrDefault(); if (student == null) { return(false); } student.InternshipCourses.Remove(internshipCourse); IMSContext.InternshipCourses.Remove(internshipCourse); IMSContext.SaveChanges(); return(true); }
public InternshipCourse ToModel(InternshipCourse internshipCourse = null) { if (internshipCourse == null) { internshipCourse = new InternshipCourse(); internshipCourse.Id = Guid.NewGuid(); } internshipCourse.End = this.End; internshipCourse.Start = this.Start; internshipCourse.StudentId = this.StudentId; internshipCourse.CompanyId = this.CompanyId; internshipCourse.LecturerId = this.LecturerId; internshipCourse.FinalScore = this.FinalScore; internshipCourse.End = this.End; internshipCourse.File = this.File; internshipCourse.LecturerComment = this.LecturerComment; internshipCourse.CompanyComment = this.CompanyComment; return(internshipCourse); }
public InternshipCourse ToModel(InternshipCourse internshipCourse = null) { if (internshipCourse == null) { internshipCourse = new InternshipCourse(); internshipCourse.Id = Guid.NewGuid(); //internshipCourse.Start = (DateTime)new SqlDateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, // DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); } internshipCourse.StudentId = this.StudentId; internshipCourse.CompanyId = this.CompanyId; internshipCourse.LecturerId = this.LecturerId; internshipCourse.FinalScore = this.FinalScore; //internshipCourse.End = this.End; internshipCourse.File = this.File; internshipCourse.LecturerComment = this.LecturerComment; internshipCourse.CompanyComment = this.CompanyComment; return(internshipCourse); }