public StudentDto ModleMapper1() { Cource cource = new Cource(); cource.ID = "1"; cource.CourceName = "数学"; cource.Grade = 80.56; Student stu = new Student(); stu.AGE = 25; stu.ID = "1"; stu.CID = "321281199505290919"; stu.NAME = "陈兆杰"; stu.Cource = cource; StudentDto stuDto = new StudentDto(); { TypeAdapterConfig config = new TypeAdapterConfig(); //建立映射关系一, NewConfig 删除任何现有配置 { config.NewConfig <Student, StudentDto>() .Map(dto => dto.ID, d => d.ID).Map(dto => dto.NAME, d => d.NAME).Map(dto => dto.CourceName, s => s.Cource.CourceName); } //建立映射关系二,而 ForType 创建或增强配置。 { // config.ForType<Student, StudentDto>() //.Map(dto => dto.ID, d => d.ID).Map(dto => dto.NAME, d => d.NAME).Map(dto => dto.CourceName, s => s.Cource.CourceName); } stuDto = stu.Adapt <StudentDto>(config);//根据config配置,映射stu实体为StudentDto类型 } return(stuDto); }
//this will be called when submission of form public ActionResult RegisterCource(Cource c, FormCollection form) { var userName = Session["UserName"]; if (userName == null) { return(RedirectToAction("LogIn")); } var StudentId = eb.T_Student.Where(x => x.UserName == userName.ToString()).FirstOrDefault().Id; var cources = eb.Cources.ToList(); var roleId = eb.T_Student.Where(x => x.UserName == userName.ToString()).FirstOrDefault().RoleId; cources = cources.Where(x => x.RoleId == roleId).ToList(); var selectedCourcesComaSeprated = form["chkCource"]; if (!string.IsNullOrEmpty(selectedCourcesComaSeprated)) { var courceId = selectedCourcesComaSeprated.Split(','); foreach (var x1 in courceId) { SaveRegisteredCource(Convert.ToInt16(x1), Convert.ToInt16(StudentId)); } TempData["Success"] = "Registered Successfullt"; ViewBag.Menus = GetMenusBasedOnUser(); } return(View(cources)); }
/// <summary> /// 资源文件地址 有关需要改变文件目录的时候需要改变的地方 /// </summary> /// <param name="cId"></param> /// <returns></returns> public IActionResult Delete([Required] int cId) { if (ModelState.IsValid) { if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager) { return(Json(new { isOk = false, title = "错误提示", message = "你并无课程管理操作权限" })); } Cource c = _context.Cources.Find(cId); if (c != null) { //先把资源文件删除掉 List <Resource> resources = _context.Resources.Where(r => r.CourceId == cId && r.ResourceType == ResourceType.Vedio).ToList(); foreach (var res in resources) { String path = Path.GetFullPath($@"{_hosting.WebRootPath}/video/{res.ResourceUrl}"); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } _context.RemoveRange(_context.Resources.Where(r => r.CourceId == cId)); _context.Cources.Remove(c); _context.SaveChanges(); return(Json(new { isOk = false, title = "消息提示", message = "删除成功!" })); } else { return(Json(new { isOk = false, title = "错误提示", message = "课程不存在,或者已经被删除" })); } } else { return(Json(new { isOk = false, error = _analysis.ModelStateDictionaryError(ModelState), title = "错误提示", message = "参数错误,传递了不符合规定的参数" })); } }
public IActionResult Update([Required] int cId, [Required] String name) { if (ModelState.IsValid) { if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager) { return(Json(new { isOk = false, title = "错误提示", message = "你并无课程管理操作权限" })); } if (_context.Cources.Any(cr => cr.Name == name)) { return(Json(new { isOk = false, title = "错误提示", message = "此课程名称已经存在!或者你没有改变课程名称!" })); } Cource c = _context.Cources.Find(cId); if (c != null) { c.Name = name.Trim(); _context.SaveChanges(); return(Json(new { isOk = true, title = "消息提示", message = "修改成功!" })); } else { return(Json(new { isOk = false, title = "错误信息", message = "课程不存在或者已经被删除了" })); } } else { return(Json(new { isOk = false, error = _analysis.ModelStateDictionaryError(ModelState), title = "错误提示", message = "参数错误,传递了不符合规定的参数" })); } }
public ActionResult DeleteCource(int id) { using (LMSContext db = new LMSContext()) { Cource std = db.Cources.Where(x => x.ID == id).FirstOrDefault <Cource>(); db.Cources.Remove(std); db.SaveChanges(); return(Json(new { success = true, message = "Записът е изтрит." }, JsonRequestBehavior.AllowGet)); } }
static void Main(string[] args) { using (ApplicationContext db = new ApplicationContext()) { Student s1 = new Student { Name = "Tom" }; Student s2 = new Student { Name = "Alice" }; Student s3 = new Student { Name = "Bob" }; db.Students.AddRange(new List <Student> { s1, s2, s3 }); Cource c1 = new Cource { Name = "Алгоритмы" }; Cource c2 = new Cource { Name = "Основы программирования" }; db.Cources.AddRange(new List <Cource> { c1, c2 }); db.SaveChanges(); // добавляем к студентам курсы s1.StudentCources.Add(new StudentCource { CourseId = c1.Id, StudentId = s1.Id }); s2.StudentCources.Add(new StudentCource { CourseId = c1.Id, StudentId = s2.Id }); s2.StudentCources.Add(new StudentCource { CourseId = c2.Id, StudentId = s2.Id }); db.SaveChanges(); var courses = db.Cources.Include(c => c.StudentCources).ThenInclude(sc => sc.Student).ToList(); // выводим все курсы foreach (var c in courses) { Console.WriteLine($"\n Course: {c.Name}"); // выводим всех студентов для данного кура var students = c.StudentCources.Select(sc => sc.Student).ToList(); foreach (Student s in students) { Console.WriteLine($"{s.Name}"); } } } Console.ReadKey(); }
public decimal?GetCourse(string currencyCodeFrom, string currencyCodeTo) { Cource course = _cources.FirstOrDefault( c => c.CurrencyFrom.CurrencyCode.Equals(currencyCodeFrom) && c.CurrencyTo.CurrencyCode.Equals(currencyCodeTo)); if (ReferenceEquals(course, null)) { return(null); } return(course.Value); }
public async Task CreateAsync(string name, string description, string trainerId, DateTime startDate, DateTime endDate) { var course = new Cource { Name = name, Description = description, StartDate = startDate, EndDate = endDate, TrainerId = trainerId }; this.db.Cources.Add(course); await this.db.SaveChangesAsync(); }
public async Task <IActionResult> Use([Required] int cId) { if (ModelState.IsValid) { if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager) { return(Json(new { isOk = false, title = "错误提示", message = "你并无课程管理操作权限" })); } Cource cource = _context.Cources.Find(cId); if (cource != null) { cource.CourceStatus = CourceStatus.Using; await _context.SaveChangesAsync(); return(Json(new { isOk = true, title = "消息提示", message = "修改成功!" })); } else { return(Json(new { isOk = false, title = "错误提示", message = "资源不存在,或者已经被删除了" })); } } else { return(Json(new { isOk = false, error = _analysis.ModelStateDictionaryError(ModelState), title = "错误提示", message = "参数错误,传递了不符合规定的参数" })); } }
public ActionResult AddCource(Cource c, FormCollection formCollection) { var selectedRoleIdComaSeprated = formCollection["selectedRole"]; var rolesId = selectedRoleIdComaSeprated.Split(','); var list = new List <Role>(); foreach (var x1 in rolesId) { InsertCource(c.CourceName, c.CourceDescription, Convert.ToInt32(x1)); } eb.SaveChanges(); ViewBag.Roles = eb.Roles.ToList(); ViewBag.Menus = GetMenusBasedOnUser(); TempData["Success"] = "Added Successfullt"; return(View()); }
public ActionResult AddOrEditCource(Cource cource) { using (LMSContext db = new LMSContext()) { if (cource.ID == 0) { db.Cources.Add(cource); db.SaveChanges(); return(Json(new { success = true, message = "Записът е успешен." }, JsonRequestBehavior.AllowGet)); } else { db.Entry(cource).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = true, message = "Редакцията е успешна." }, JsonRequestBehavior.AllowGet)); } } }
/// <summary> /// Метод позволяющий сгенерировать данные рандомно /// </summary> public override void FillPropertiesRandomly() { base.FillPropertiesRandomly(); this.StudentFaculty = (Faculty)Rnd.Next(1, 4); this.StudentCource = (Cource)Rnd.Next(1, 5); }
public ViewModels.ReportView QueryResults(int? courseId, string grade, int? statusId, Student student, Enrollments enrollment, Cource course) { if ((courseId != null) && (courseId != course)) { return null; } if ((!string.IsNullOrEmpty(grade)) && (grade != enrollment.Grade)) { return null; } if ((statusId != null) && (statusId != student.StatusID)) { return null; } return new ViewModels.ReportView { ID = student.ID, Name = student.FirstName + " " + student.LastName, Course = course.Title, Grade = enrollment.Grade, GraduationDate = student.GraduationDate, Status = student.Status.Title }); }
protected override void Seed(Exercises.Data.StudentSystemContext context) { Student student = new Student() { Name = "Thinh", RegistrationDate = new DateTime(2017, 3, 1), BirthDate = new DateTime(1988, 6, 23) }; Student student2 = new Student() { Name = "Tai", RegistrationDate = new DateTime(2017, 3, 1), BirthDate = new DateTime(1990, 8, 10) }; Student student3 = new Student() { Name = "Truc", RegistrationDate = new DateTime(2017, 3, 1), BirthDate = new DateTime(1994, 3, 7) }; context.Students.AddOrUpdate(s => s.Name, student); context.Students.AddOrUpdate(s => s.Name, student2); context.Students.AddOrUpdate(s => s.Name, student3); context.SaveChanges(); Resource resource = new Resource() { Name = "Sample", ResourceType = ResourceType.Document, Url = "www.thanhthinh.com" }; Resource resource2 = new Resource() { Name = "Sample2", ResourceType = ResourceType.Presentation, Url = "www.thanhthinh1.com" }; Resource resource3 = new Resource() { Name = "Sample3", ResourceType = ResourceType.Video, Url = "www.thanhthinh2.com" }; context.Resources.AddOrUpdate(r => r.Name, resource); context.Resources.AddOrUpdate(r => r.Name, resource2); context.Resources.AddOrUpdate(r => r.Name, resource3); context.SaveChanges(); Homework homework = new Homework() { Content = "Homework", ContentType = ContentType.Application, SubmissionDate = new DateTime(2017, 4, 8), Student = student }; Homework homework2 = new Homework() { Content = "Homework2", ContentType = ContentType.Application, SubmissionDate = new DateTime(2017, 4, 8), Student = student2 }; Homework homework3 = new Homework() { Content = "Homework3", ContentType = ContentType.Application, SubmissionDate = new DateTime(2017, 3, 8), Student = student3 }; context.Homeworks.AddOrUpdate(h => h.Content, homework); context.Homeworks.AddOrUpdate(h => h.Content, homework2); context.Homeworks.AddOrUpdate(h => h.Content, homework3); context.SaveChanges(); Cource course = new Cource() { Name = "C# DB Advanced", Description = "DB Course for advanced students", StartDate = new DateTime(2017, 3, 8), EndDate = new DateTime(2017, 3, 8), Price = 200.00m, Students = { student, student2, student3 }, HomeworkSubmissions = { homework, homework2, homework3 }, Resources = { resource, resource2, resource3 } }; context.Cources.AddOrUpdate(course); context.SaveChanges(); }
public IActionResult Create([Required] String name, [Required] int moduleId, [Required] float mark, [Required] String description) { if (ModelState.IsValid) { if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager) { return(Json(new { isOk = false, title = "错误提示", message = "你并无课程管理操作权限" })); } if (!_context.Modules.Any(m => m.ModuleId == moduleId)) { return(Json(new { isOk = false, title = "错误提示", message = "模块不存在,或者已经被删除" })); } if (_context.Cources.Any(c => c.Name == name)) { return(Json(new { isOk = false, title = "错误提示", message = "此课程已经存在了" })); } else { Cource cource = new Cource { Name = name.Trim(), AddTime = DateTime.Now, CourceStatus = CourceStatus.Normal, Credit = mark, Introduction = description.Trim(), ModuleId = moduleId }; _context.Cources.Add(cource); _context.SaveChanges(); return(Json(new { isOk = false, title = "消息提示", message = "添加成功!" })); } } else { return(Json(new { isOk = false, error = _analysis.ModelStateDictionaryError(ModelState), title = "错误提示", message = "参数错误,传递了不符合规定的参数" })); } }