protected (ClassViewModel ServedType, ClassViewModel DeclaredFor) GetStrategyTypes( ModelBindingContext bindingContext, Type strategyInterface ) { // Grab the type information about what we need to inject. var parameterTypeViewModel = new ReflectionTypeViewModel(bindingContext.ModelType); // Figure out what type is satisfying the generic parameter of our strategy interface. // This is the type that our datasource/Behaviors needs to serve. var servedType = parameterTypeViewModel.GenericArgumentsFor(strategyInterface).Single().ClassViewModel; // Examine the parameter for any attributes. var parameterDescriptor = bindingContext.ActionContext.ActionDescriptor.Parameters .Single(p => p.Name == bindingContext.FieldName) as Microsoft.AspNetCore.Mvc.Controllers.ControllerParameterDescriptor; var parameterInfo = parameterDescriptor.ParameterInfo; var declaredForAttribute = parameterInfo.GetAttribute <DeclaredForAttribute>(); // See if there is an override for the type that we want to find declared data sources for. ClassViewModel declaredFor = servedType; if (declaredForAttribute != null) { declaredFor = ReflectionRepository.Global.GetClassViewModel(declaredForAttribute.DeclaredFor); } return(servedType, declaredFor); }
public IActionResult Edit(ClassViewModel model) { var response = ResponseModelFactory.CreateInstance; if (model.SchoolUuid == null && AuthContextService.CurrentUser.SchoolGuid == null) { response.SetFailed("请登录学校账号"); return(Ok(response)); } using (_dbContext) { var entity = _dbContext.Class.FirstOrDefault(x => x.ClassUuid == model.ClassUuid && x.IsDelete == 0); if (entity == null) { response.SetFailed("该班级不存在"); return(Ok(response)); } if (entity.ClassName != model.ClassName && _dbContext.Class.Any(x => x.IsDelete == 0 && x.ClassName == model.ClassName && x.SchoolUuid == AuthContextService.CurrentUser.SchoolGuid)) { response.SetFailed("已存在该班级名称"); return(Ok(response)); } entity.ClassName = model.ClassName; var num = _dbContext.SaveChanges(); if (num > 0) { response.SetSuccess("修改成功"); } else { response.SetFailed("未修改"); } return(Ok(response)); } }
public IActionResult Create(ClassViewModel model) { var response = ResponseModelFactory.CreateInstance; if (model.SchoolUuid == null && AuthContextService.CurrentUser.SchoolGuid == null) { response.SetFailed("请登录学校账号"); return(Ok(response)); } using (_dbContext) { if (_dbContext.Class.Any(x => x.IsDelete == 0 && x.ClassName == model.ClassName && x.SchoolUuid == AuthContextService.CurrentUser.SchoolGuid)) { response.SetFailed("已存在该班级名称"); return(Ok(response)); } var entity = new Entities.Class(); entity.ClassUuid = Guid.NewGuid(); //entity.SchoolUuid = model.SchoolUuid; entity.IsDelete = 0; entity.ClassName = model.ClassName; entity.SchoolUuid = AuthContextService.CurrentUser.SchoolGuid; _dbContext.Class.Add(entity); _dbContext.SaveChanges(); response.SetSuccess(); return(Ok(response)); } }
private void OnClickCreateItem(MouseButtonEventArgs e) { ItemViewModel item = null; var position = e.MouseDevice.GetPosition(e.Source as IInputElement); if (IsAddingClassPressed) { item = new ClassViewModel() { X = position.X, Y = position.Y }; IsAddingClassPressed = false; } else if (IsAddingTextBoxPressed) { item = new TextBoxViewModel() { X = position.X, Y = position.Y }; IsAddingTextBoxPressed = false; } if (item != null) { commandController.AddAndExecute(new AddItemCommand(Items, item)); StatusBarMsg = item.Type + " have been added on postions {" + position.X + ";" + position.Y + "}"; } }
public async Task <ActionResult> Create([Bind(Include = "Id,Name,FacultyId,LecturerId,SchoolYear,DegreeLevel,TypeOfEducation")] ClassViewModel classViewModel) { if (ModelState.IsValid) { Class @class = new Class { Name = classViewModel.Name, FacultyId = classViewModel.FacultyId, //LecturerId = classViewModel.LecturerId, DegreeLevel = classViewModel.DegreeLevel, SchoolYear = classViewModel.SchoolYear, TypeOfEducation = classViewModel.TypeOfEducation }; @class.Faculty = db.Faculties.Where(c => c.Id == classViewModel.FacultyId).First(); @class.Lecturer = db.Lecturers.Where(c => c.LecturerCode == classViewModel.LecturerId).First(); @class.FacultyId = @class.Faculty.Id; @class.LecturerId = @class.Lecturer.Id; db.Classes.Add(@class); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(classViewModel)); }
public ActionResult Edit([Bind(Include = "Id,Name,Subject")] ClassViewModel @class, int selectedTeacher, int selectedPupil) { @class.Teachers.Clear(); @class.Pupils.Clear(); if (selectedTeacher != 0 && selectedPupil != 0) { var p = schoolService.GetPupil(selectedPupil); var mappe = new MapperConfiguration(cfg => cfg.CreateMap <PupilDTO, PupilViewModel>()).CreateMapper(); var pup = mappe.Map <PupilDTO, PupilViewModel>(p); @class.Pupils.Add(pup); var t = schoolService.GetTeacher(selectedTeacher); var mappe1 = new MapperConfiguration(cfg => cfg.CreateMap <TeacherDTO, TeacherViewModel>()).CreateMapper(); var tech = mappe.Map <TeacherDTO, TeacherViewModel>(t); @class.Teachers.Add(tech); } if (ModelState.IsValid) { var mapper = new MapperConfiguration(cfg => cfg.CreateMap <ClassViewModel, ClassDTO>()).CreateMapper(); var _class = mapper.Map <ClassViewModel, ClassDTO>(@class); schoolService.Edit(_class); return(RedirectToAction("Index")); } return(View(@class)); }
/// <summary> /// Write the metadata for all data sources of a class /// </summary> private void WriteDataSourcesMetadata(TypeScriptCodeBuilder b, ClassViewModel model) { using (b.Block("dataSources:", ',')) { var dataSources = model.ClientDataSources(this.Model); foreach (var source in dataSources) { WriteDataSourceMetadata(b, model, source); } // Not sure we need to explicitly declare the default source. // We can just use the absense of a data source to represent the default. /* * var defaultSource = dataSources.SingleOrDefault(s => s.IsDefaultDataSource); * if (defaultSource != null) * { * var name = defaultSource.ClientTypeName.ToCamelCase(); * b.Line($"get default() {{ return this.{name} }},"); * } * else * { * using (b.Block($"default:", ',')) * { * b.StringProp("type", "dataSource"); * b.StringProp("name", "default"); * b.StringProp("displayName", "Default"); * b.Line("params: {}"); * } * } */ } }
public ActionResult Edit(ClassViewModel model, int?id) { if (ModelState.IsValid) { var a = db.Classes.Find(id); var ClassModel = new ClassViewModel { class_id = a.class_id, subject_id = a.subject_id, classroom_id = a.classroom_id, user_id = a.user_id, schedule_id = a.schedule_id, group_no = a.group_no, time_start = a.Schedule.time_start, time_end = a.Schedule.time_end, day = a.Schedule.day, room_number = a.Classroom.room_number }; var chk1 = (from x in db.Subjects where x.course_id == model.course_id select x).FirstOrDefault(); var cls = db.Classes.Find(model.class_id); cls.group_no = model.group_no; cls.subject_id = chk1.subject_id; var classroom = db.Classrooms.Find(ClassModel.classroom_id); classroom.classroom_id = (int)ClassModel.classroom_id; classroom.room_number = model.room_number; var sched = db.Schedules.Find(ClassModel.schedule_id); sched.time_start = model.time_start; sched.time_end = model.time_end; sched.day = ClassModel.day; var user = db.Users.Find(model.user_id); user.user_id = (int)model.user_id; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.classroom_id = new SelectList(db.Classrooms, "classroom_id", "room_number", model.classroom_id); ViewBag.schedule_id = new SelectList(db.Schedules, "schedule_id", "day", model.schedule_id); ViewBag.subject_id = new SelectList(db.Subjects, "subject_id", "subject_name", model.subject_id); ViewBag.course_id = new SelectList(db.Courses, "course_id", "courseno", model.course_id); ViewBag.user_id = new SelectList(db.Users, "user_id", "f_name", model.user_id); return(View(model)); }
/// <summary> /// 搜索我的班级数据 /// </summary> /// <param name="webModel">班级列表页视图模型</param> /// <param name="context">数据库上下文对象</param> /// <returns></returns> public async Task <ClassViewModel> SearchClassAsync(ClassViewModel webModel, ApplicationDbContext context) { try { //Source Data List var list = await UserRepository.GetListAsync(webModel, context); //Return Data List var dataList = new List <ClassData>(); if (list != null && list.Any()) { dataList.AddRange(list.Select(item => new ClassData { Id = item.Id.ToString(), Name = item.Name, Department = item.DepartmentName, QQNumber = !string.IsNullOrEmpty(item.QQ) ? item.QQ : " ", Wechat = !string.IsNullOrEmpty(item.Wechat) ? item.Wechat : " ", SessionNum = item.SessionNum + "级", MajorName = item.MajorName, MajorCode = item.MajorCode, })); } webModel.ClassList = dataList; webModel.Total = await UserRepository.GetListCountAsync(webModel, context); } catch (Exception ex) { _logger.LogError("获取我的班级列表失败:{0},\r\n内部错误信息:{1}", ex.Message, ex.InnerException.Message); } return(webModel); }
public async Task <IActionResult> Search(string filter, string value, int isUsageTeacher) { Guid?userLogin = null; if (isUsageTeacher == 1) { userLogin = userId; } var ret = await this._unitOfWork.Classes.Search(filter, value, userLogin, this._unitOfWork.Branches.GetAllBranchOfUserString(userId)); List <ClassViewModel> list = new List <ClassViewModel>(); if (ret != null) { foreach (var c in ret) { var item = new ClassViewModel(); var material = await this._unitOfWork.Materials.Get(c.MaterialId); item.MaterialName = material != null ? material.MaterialName : string.Empty; item.ID = c.ClassId; item.Code = c.ClassCode; item.Name = c.ClassName; item.Note = c.Note; item.StartDate = c.StartDate; item.EndDate = c.EndDate; list.Add(item); } } return(this.Ok(list)); }
private static void WriteListViewModel(TypeScriptCodeBuilder b, ClassViewModel model) { string name = model.ViewModelClassName; string viewModelName = $"{model.ListViewModelClassName}ViewModel"; string metadataName = $"$metadata.{name}"; using (b.Block($"export class {viewModelName} extends ListViewModel<$models.{name}, $apiClients.{name}ApiClient>")) { foreach (var method in model.ClientMethods.Where(m => m.IsStatic)) { string signature = string.Concat(method.ClientParameters.Select(f => $", {f.Name}: {new VueType(f.Type).TsType("$models")} | null")); // "item" or "list" var transportTypeSlug = method.TransportType.ToString().Replace("Result", "").ToLower(); b.DocComment(method.Comment, true); b.Line($"public {method.JsVariable} = this.$apiClient.$makeCaller(\"{transportTypeSlug}\", "); b.Indented($"(c{signature}) => c.{method.JsVariable}({string.Join(", ", method.ClientParameters.Select(p => p.Name))}))"); } b.Line(); using (b.Block($"constructor()")) { b.Line($"super({metadataName}, new $apiClients.{name}ApiClient())"); } } b.Line(); }
public async Task <IActionResult> GetFirstClass(Guid?index) { var c = await this._unitOfWork.Classes.Get(index); var itemExist = new ClassViewModel(); if (c != null) { var itemMate = await this._unitOfWork.Materials.Get(c.MaterialId); itemExist = new ClassViewModel { ID = c.ClassId, Code = c.ClassCode, Name = c.ClassName, Note = c.Note, BranchId = c.BranchId, EndDate = c.EndDate, StartDate = c.StartDate, LongLearn = c.LongLearn, MaterialId = c.MaterialId, MaxStudent = c.MaxStudent, StatusId = c.StatusId, SupplierId = c.SupplierId, MaterialName = itemMate != null ? itemMate.MaterialName : string.Empty }; } return(Ok(itemExist)); }
public ActionResult ViewStudentList(ClassViewModel collection) { string id = User.Identity.GetUserId(); var p = db.AspNetUsers.Where(x1 => x1.Id.ToString() == id).SingleOrDefault(); //Condition to check the Id of specific person to edit only his/her details string email = p.Email; var p1 = db.Teachers.Where(x1 => x1.Email == email).SingleOrDefault(); //Condition to check the Id of specific person to edit only his/her details y.ClassName = collection.ClassName; y.SectionName = collection.SectionName; UserAccountViewModel userL = new UserAccountViewModel(); var list = db.StudentClasses.ToList(); foreach (var i in list) { if (i.Class.ClassName == collection.ClassName && i.Section.SectionName == collection.SectionName) { RegisterViewModel v = new RegisterViewModel(); v.Id = i.Student.StudentID; v.FirstName = i.Student.FirstName; v.LastName = i.Student.LastName; v.Gender = i.Student.Gender; v.RegistrationNo = i.Student.RegistrationNo; userL.listofusers.Add(v); } } comboreload(); return(View(userL)); }
/// <summary> /// Finds the units by staff id. /// </summary> /// <param name="staffId">The staff id.</param> public List <ClassViewModel> FindClassesByStaffId(int staffId) { List <ClassViewModel> models = new List <ClassViewModel>(); try { List <Unit> units = UnitManager.FindUnitsByStaffId(staffId); foreach (Unit unit in units) { ClassViewModel obj = new ClassViewModel(); obj.Title = unit.Title; obj.Id = unit.Id; obj.VideoAssets = ObjectMapper.Map <Model.Entities.Video, VideoViewModel>(unit.Video); obj.DocumentAssets = ObjectMapper.Map <Model.Entities.Document, DocumentViewModel>(unit.Document); obj.ListAsignment = ObjectMapper.Map <Model.Entities.Assignment, AssignmentViewModel>(unit.Assignments); obj.ListScheduleViewModel = ObjectMapper.Map <Model.Entities.Schedule, ScheduleViewModel>(unit.Schedules); obj.DepartmentViewModel = ObjectMapper.Map <Model.Entities.Department, DepartmentViewModel>(unit.Module.CourseModules.Select(p => p.Course.Department).ToList()); models.Add(obj); } } catch (Exception ex) { ExceptionManager.HandleException(ex, PolicyNameType.ExceptionReplacing); } return(models); }
public void OnClassChangedTest() { bool isCalled = false; var factory = new PropertyFactory(); var prop = new ClassProperty(typeof(MyClass), factory); var vm = new ClassViewModel(prop, new ViewModelFactory(factory, false)); vm.OnChanged.Subscribe(x => isCalled = true); var memberY = vm.Members.OfType <IntViewModel>() .Where(x => x.Property.PropertyInfo.Name == nameof(MyClass.Y)) .First(); memberY.IntValue.Value = 99; isCalled.IsTrue(); isCalled = false; var memberZ = vm.Members.OfType <IntViewModel>() .Where(x => x.Property.PropertyInfo.Name == nameof(MyClass.Z)) .First(); memberZ.IntValue.Value = 81; isCalled.IsTrue(); }
private static string GetClassMetadataRef(ClassViewModel obj = null) { // We need to qualify with "domain." instead of the exported const // because in the case of a self-referential property, TypeScript can't handle recursive implicit type definitions. return($"(domain.types.{obj.ViewModelClassName} as {(obj.IsDbMappedType ? "ModelType" : "ObjectType")})"); }
private async void CreateClass_OnClick(object sender, EventArgs e) { Debug.WriteLine(Class.ClassType); Debug.WriteLine(Class.UnitCode); Debug.WriteLine(Class.Location); if (Class.ClassType.Length == 0 || Class.UnitCode.Length == 0 || Class.Location.Length == 0) { await DisplayAlert("Oops!", "Please fill in every field!", "OK"); } else { Class.DateAndTime = Class.DateAndTime.Add(Time); ClassViewModel viewModel = (ClassViewModel)Application.Current.Resources["ClassViewModel"]; viewModel.add(Class, endDate); if (viewModel.Repeat) { while (true) { if (Class.DateAndTime.AddDays(7).Date <= endDate.Date) { Class.DateAndTime = Class.DateAndTime.AddDays(7); await viewModel.add(Class); } else { break; } } } await Navigation.PopAsync(); } }
private void SelectPrevious() { if (_classes.Any()) { ClassListItemViewModel selected = _classes.FirstOrDefault(x => x.IsSelected); foreach (ClassListItemViewModel c in _classes) { c.IsSelected = false; } if (selected == null) { _classes[_classes.Count - 1].IsSelected = true; _selectedClass = new ClassViewModel(_classes[_classes.Count - 1].ClassModel); } else { int index = Math.Max(_classes.IndexOf(selected) - 1, 0); _classes[index].IsSelected = true; _selectedClass = new ClassViewModel(_classes[index].ClassModel); } OnPropertyChanged(nameof(SelectedClass)); } }