public IHttpActionResult TaoLop(CreateClassModel model) { IHttpActionResult httpActionResult; ErrorModel errors = new ErrorModel(); if (string.IsNullOrEmpty(model.MaLop)) { errors.Add("Mã lớp là trường bắt buộc!"); } if (errors.Errors.Count == 0) { Lop lop = new Lop(); lop.MaLop = model.MaLop; lop.TenLop = model.TenLop; //lop.GVCN_ID = model.GVCN_ID; lop = _db.Lops.Add(lop); this._db.SaveChanges(); LopModel viewModel = new LopModel(lop); httpActionResult = Ok(viewModel); } else { httpActionResult = Ok(errors); } return(httpActionResult); }
public IHttpActionResult CreateClass(CreateClassModel model) { IHttpActionResult httpActionResult; ErrorModel error = new ErrorModel(); if (string.IsNullOrEmpty(model.ClassId)) { error.Add("Mã lớp là bắt buộc"); } if (string.IsNullOrEmpty(model.ClassName)) { error.Add("Tên lớp là bắt buộc"); } if (_db.Teacher.FirstOrDefault(m => m.Id == model.Homeroom_Teacher) == null) { error.Add("Giáo viên không tồn tại"); } if (error.Errors.Count == 0) { Class oneClass = new Class(); oneClass.ClassName = model.ClassName; oneClass.ClassId = model.ClassId; oneClass.LearningTime = model.LearningTime; oneClass.Homeroom = _db.Teacher.FirstOrDefault(m => m.Id == model.Homeroom_Teacher); oneClass = this._db.Class.Add(oneClass); this._db.SaveChanges(); ClassModel viewModel = new ClassModel(oneClass); httpActionResult = Ok(viewModel); } else { httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, error); } return(httpActionResult); }
public IActionResult Create() { var groupTrainings = this.groupTrainingsService.GettAll <ClassGroupTrainingInListViewModel>(); var trainers = this.trainersService.GetAll <ClassTrainersInListViewModel>(); var viewModel = new CreateClassModel { GroupTrainings = groupTrainings, Trainers = trainers, }; return(this.View(viewModel)); }
public async Task <ActionResult> CreateClass(CreateClassModel model) { Class tmp_class = new Class(); tmp_class.id = ""; tmp_class.id += model.grade + model.letter; tmp_class.teacher_id = model.teacher; using (var appContext = new TimetableEntities()) { appContext.Class.Add(tmp_class); await appContext.SaveChangesAsync(); } return(RedirectToAction("Class")); }
private string CreateCsFile(string path, CreateClassModel model) { path = Directory.GetCurrentDirectory() + path; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var fileName = path + $"{model.Name}.cs"; if (File.Exists(fileName)) { File.Delete(fileName); } File.WriteAllText(fileName, CreateClass(model)); return(fileName); }
public IHttpActionResult Create(CreateClassModel model) { IHttpActionResult httpActionResult; ErrorModel errors = new ErrorModel(); if (string.IsNullOrEmpty(model.MaLop)) { errors.Add("Mã lớp là trường bắt buộc"); } if (string.IsNullOrEmpty(model.TenLop)) { errors.Add("Tên lớp là trường bắt buộc"); } if (_db.Teacher.FirstOrDefault(m => m.Id == model.GVCN_Id) == null) { errors.Add("ID Giáo viên chủ nhiệm trống hoặc không tồn tại"); } if (errors.Errors.Count == 0) { Classes lop = new Classes(); lop.Malop = model.MaLop; lop.Tenlop = model.TenLop; lop.GiaoVienChuNhiem = _db.Teacher.FirstOrDefault(m => m.Id == model.GVCN_Id); lop = _db.Class.Add(lop); this._db.SaveChanges(); ClassModel viewModel = new ClassModel(lop); httpActionResult = Ok(viewModel); } else { httpActionResult = new ErrorActionResult(Request, System.Net.HttpStatusCode.BadRequest, errors); } return(httpActionResult); }
public async Task <IActionResult> Create(CreateClassModel classModel) { if (!this.ModelState.IsValid) { classModel.GroupTrainings = this.groupTrainingsService.GettAll <ClassGroupTrainingInListViewModel>(); classModel.Trainers = this.trainersService.GetAll <ClassTrainersInListViewModel>(); return(this.View(classModel)); } if (classModel.EndHour <= classModel.StartHour) { classModel.GroupTrainings = this.groupTrainingsService.GettAll <ClassGroupTrainingInListViewModel>(); classModel.Trainers = this.trainersService.GetAll <ClassTrainersInListViewModel>(); this.ModelState.AddModelError(string.Empty, InvalidHours); return(this.View(classModel)); } var classes = this.classesService.GettAll <ClassInListViewModel>(); if (classes.Any(x => x.StartHour == classModel.StartHour && x.DayOfWeek == classModel.DayOfWeek)) { classModel.GroupTrainings = this.groupTrainingsService.GettAll <ClassGroupTrainingInListViewModel>(); classModel.Trainers = this.trainersService.GetAll <ClassTrainersInListViewModel>(); this.ModelState.AddModelError(string.Empty, DayAndTimeIsTakenError); return(this.View(classModel)); } var serviceModel = AutoMapperConfig.MapperInstance.Map <CreateClassServiceModel>(classModel); await this.classesService.CreateAsync(serviceModel); return(this.RedirectToAction("Index")); }
public IHttpActionResult TaoLop(CreateClassModel model) { IHttpActionResult httpActionResult; ErrorModel errors = new ErrorModel(); if (string.IsNullOrEmpty(model.MaLop)) { errors.Add("Mã lop la bat buoc"); } if (string.IsNullOrEmpty(model.TenLop)) { errors.Add("Tên lop la bayt buoc"); } if (errors.Errors.Count == 0) { Lop lop = new Lop(); lop.MaLop = model.MaLop; lop.TenLop = model.TenLop; lop = _db.Lops.Add(lop); this._db.SaveChanges(); ClassModel viewModel = new ClassModel(lop); httpActionResult = Ok(viewModel); } else { httpActionResult = Ok(errors); } return(httpActionResult); }
private string CreateClass(CreateClassModel model) { var str = ""; foreach (var item in model.Imports) { str += $"using {item};\n"; } if (model.Imports.Any()) { str += "\n"; } str += $"namespace {model.Namespace}\n"; str += "{\n"; str += $"\tpublic class {model.Name}"; if (!string.IsNullOrEmpty(model.Dependency)) { str += $" : {model.Dependency}"; } str += "\n"; str += "\t{\n"; foreach (var item in model.Properties) { str += CreateProperty(item.Key, item.Value); } str += "\t}\n"; str += "}"; return(str); }
public void Export() { var saveDir = "/Models/Entities/"; var tables = _tableManager.BaseQuery().Include(x => x.Columns).ToList(); foreach (var item in tables) { var model = new CreateClassModel() { Dependency = "Entry", Namespace = $"{App.Common.SiteInformation.WebProjectName}.Models.Entities", Name = item.Name, Imports = new List <string>() { "Haro.AdminPanel.Models.Entities" } }; foreach (var column in item.Columns) { switch (column.ColumnType) { case ColumnType.Text: case ColumnType.Password: case ColumnType.TextArea: case ColumnType.Editor: case ColumnType.Image: case ColumnType.Number: case ColumnType.Bool: case ColumnType.Slug: model.Properties.Add( new KeyValuePair <string, string>(ColumnTypeToStr(column.ColumnType), column.Name)); break; case ColumnType.SelectList: model.Imports.Add("System.Collections.Generic"); model.Properties.Add(new KeyValuePair <string, string>(column.TargetTable, column.Name)); model.Properties.Add(new KeyValuePair <string, string>("long", column.Name + "Id")); break; case ColumnType.MultipleSelectList: model.Imports.Add("System.Collections.Generic"); model.Properties.Add(new KeyValuePair <string, string>( $"List<{column.Table.Name}{column.Name}Image>", column.Name)); CreateCsFile(saveDir, new CreateClassModel() { Name = item.Name + column.TargetTable, Namespace = $"{App.Common.SiteInformation.WebProjectName}.Models.Entities", Properties = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>(item.Name, item.Name), new KeyValuePair <string, string>("long", item.Name + "Id"), new KeyValuePair <string, string>(column.TargetTable, column.TargetTable), new KeyValuePair <string, string>("long", column.TargetTable + "Id"), } }); break; case ColumnType.MultipleImage: model.Imports.Add("System.Collections.Generic"); model.Properties.Add(new KeyValuePair <string, string>( $"List<{item.Name}Image>", item.Name + "Image")); CreateCsFile(saveDir, new CreateClassModel() { Name = item.Name + "Image", Namespace = $"{App.Common.SiteInformation.WebProjectName}.Models.Entities", Properties = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>(item.Name, item.Name), new KeyValuePair <string, string>("long", item.Name + "Id"), new KeyValuePair <string, string>("string", "Image"), } }); break; case ColumnType.Hidden: break; default: throw new ArgumentOutOfRangeException(); } } CreateCsFile(saveDir, model); } }