public SchoolDetails Get(int id) { var schoolEntity = this.data.Get(id); var schoolModel = new SchoolDetails(schoolEntity); return(schoolModel); }
// GET: SchoolDetails/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SchoolDetails schoolDetails = db.SchoolDetails.Find(id); if (schoolDetails == null) { return(HttpNotFound()); } var ward = db.Ward.Where(i => i.Id == schoolDetails.WardId).Include(c => c.Constituency); int selectedWard = ward.Select(i => i.Id).First(); int selectedConstituency = ward.Select(i => i.ConstituencyId).First(); var Constituency = db.Constituency.Find(selectedConstituency); int selectedCounty = Constituency.CountyId; int selectedPC = db.PostalCode.Where(i => i.Id == schoolDetails.PostalCodeId).Select(c => c.Code).First(); ViewBag.PostalCodeId = new SelectList(db.PostalCode.OrderBy(p => p.PostalName), "Code", "PostalName", selectedPC); ViewBag.WardId = new SelectList(db.Ward.OrderBy(w => w.Name), "Id", "Name", selectedWard); ViewBag.ConstituencyId = new SelectList(db.Constituency.OrderBy(c => c.Name), "Id", "Name", selectedConstituency); ViewBag.CountyId = new SelectList(db.County.OrderBy(c => c.CountyName), "Id", "CountyName", selectedCounty); return(View(schoolDetails)); }
public ActionResult Edit([Bind(Include = "Id,Name,PhoneNumber,EmailAddress,MobileNumber,PostalAddress,PostalCodeId,WardId,SchoolLogoUrl,CreateBy,CreateDate,ModifyBy,ModifyDate")] SchoolDetails schoolDetails, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Data/SchoolLogo/"), fileName); file.SaveAs(path); schoolDetails.SchoolLogoUrl = Url.Content("~/Data/SchoolLogo/" + fileName); } int postId = db.PostalCode.Where(p => p.Code == schoolDetails.PostalCodeId).Select(i => i.Id).FirstOrDefault(); schoolDetails.PostalCodeId = postId; db.Entry(schoolDetails).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } var ward = db.Ward.Where(i => i.Id == schoolDetails.WardId).Include(c => c.Constituency); int selectedWard = ward.Select(i => i.Id).First(); int selectedConstituency = ward.Select(i => i.ConstituencyId).First(); var Constituency = db.Constituency.Find(selectedConstituency); int selectedCounty = Constituency.CountyId; int selectedPC = db.PostalCode.Where(i => i.Id == schoolDetails.PostalCodeId).Select(c => c.Code).First(); ViewBag.PostalCodeId = new SelectList(db.PostalCode.OrderBy(p => p.PostalName), "Code", "PostalName", selectedPC); ViewBag.WardId = new SelectList(db.Ward.OrderBy(w => w.Name), "Id", "Name", selectedWard); ViewBag.ConstituencyId = new SelectList(db.Constituency.OrderBy(c => c.Name), "Id", "Name", selectedConstituency); ViewBag.CountyId = new SelectList(db.County.OrderBy(c => c.CountyName), "Id", "CountyName", selectedCounty); return(View(schoolDetails)); }
public ActionResult DeleteConfirmed(int id) { SchoolDetails schoolDetails = db.SchoolDetails.Find(id); db.SchoolDetails.Remove(schoolDetails); db.SaveChanges(); return(RedirectToAction("Index")); }
public IEnumerable <SchoolDetails> Get() { var schoolEntities = this.data.All().ToList(); var schoolModels = new List <SchoolDetails>(); foreach (var student in schoolEntities) { SchoolDetails studentModel = new SchoolDetails(student); schoolModels.Add(studentModel); } return(schoolModels); }
// GET: SchoolDetails/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SchoolDetails schoolDetails = db.SchoolDetails.Find(id); if (schoolDetails == null) { return(HttpNotFound()); } return(View(schoolDetails)); }
public ActionResult SchoolAdminDashboard(string schooluid, int pageno = 1, int pagesize = 0) { if (pagesize <= 0) { pagesize = _pageSize; } var user = _authService.CurrentUserData; var modelapi = _webClient.DownloadData <SchoolDetailsResult>("getschooladmindashboard", new { PageIndex = pageno, PageSize = pagesize, UserId = user.UserId, SchoolUId = schooluid }); if (modelapi != null && modelapi.APIStatus != SchoolStatusEnum.NoSchoolFound) { if (user.SchoolUId != schooluid) { return(RedirectToRoute("UnauthorizedAccess")); } SchoolDetails model = new SchoolDetails(); model.SchoolDetail = modelapi.SchoolDetails; var Students = new Webdiyer.WebControls.Mvc.PagedList <StudentRegistrationModel>(modelapi.Students.Items, pageno, pagesize, modelapi.Students.TotalItems); model.Students = Students; model.Grades = modelapi.Grades; if (MvcSiteMapProvider.SiteMaps.Current.CurrentNode != null) { if ((model.SchoolDetail.SchoolName).Length > 20) { MvcSiteMapProvider.SiteMaps.Current.CurrentNode.Title = (model.SchoolDetail.SchoolName).Substring(0, 20) + "..."; } else { MvcSiteMapProvider.SiteMaps.Current.CurrentNode.Title = model.SchoolDetail.SchoolName; } } return(View("SchoolAdminDashboard", model)); } else { return(RedirectToRoute("PageNotFound")); } }
// GET api/Students/5 public SchoolDetails GetStudent(int id) { DbSchoolRepository schoolRepository = this.allRepositories.GetSchoolRepository(); var school = schoolRepository.Get(id); var schoolDetails = new SchoolDetails() { Id = school.Id, Name = school.Name, Location = school.Location, Students = (from student in school.Students select new StudentModel() { Id = student.Id, FirstName = student.FirstName, LastName = student.LastName, Age = student.Age, Grade = student.Grade }).ToList() }; return(schoolDetails); }
public ActionResult Create([Bind(Include = "Id,Name,PhoneNumber,EmailAddress,MobileNumber,PostalAddress,PostalCodeId,WardId,SchoolLogoUrl,CreateBy,CreateDate,ModifyBy,ModifyDate")] SchoolDetails schoolDetails, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Data/SchoolLogo/"), fileName); file.SaveAs(path); schoolDetails.SchoolLogoUrl = Url.Content("~/Data/SchoolLogo/" + fileName); } int postId = db.PostalCode.Where(p => p.Code == schoolDetails.PostalCodeId).Select(i => i.Id).FirstOrDefault(); schoolDetails.PostalCodeId = postId; db.SchoolDetails.Add(schoolDetails); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PostalCodeId = new SelectList(db.PostalCode, "Id", "PostalName", schoolDetails.PostalCodeId); ViewBag.WardId = new SelectList(db.Ward, "Id", "Name", schoolDetails.WardId); ViewBag.CountyId = db.County.OrderBy(c => c.CountyName).ToList(); return(View(schoolDetails)); }
protected async override Task <int> OnExecuteAsync(CommandLineApplication app) { if (string.IsNullOrEmpty(AppConfig.SchoolName) || AppConfig.Users.Count == 0) { Log.Error("学校名称或账号列表为空! 请先执行 init 指令初始化配置文件。"); return(1); } CpdailyCore cpdaily = new CpdailyCore(); string SchoolName = AppConfig.SchoolName; string cookies = null; SchoolDetails schoolDetails = null; try { Log.Information("正在获取 {info} ...", "SecretKey"); var secretKeyTask = cpdaily.GetSecretKeyAsync(); Log.Information("正在获取 {info} ...", "学校列表"); var schools = await cpdaily.GetSchoolsAsync(); Log.Information("正在获取 {info} ...", "学校ID"); var school = schools.Where(x => x.Name == SchoolName).FirstOrDefault(); var schoolDetailsTask = cpdaily.GetSchoolDetailsAsync(school, await secretKeyTask); Type loginWorkerType = Utils.GetLoginWorkerByName(SchoolName); ILoginWorker loginWorker = null; if (loginWorkerType != null) { Log.Information("使用专门登录适配器 <{LoginWorkerTypeName}>", loginWorkerType.Name); loginWorker = (ILoginWorker)Activator.CreateInstance(loginWorkerType); } else { Log.Information("使用通用登录适配器 <{LoginWorkerTypeName}>", "DefaultLoginWorker"); loginWorker = new DefaultLoginWorker(); } Log.Information("正在获取登录所需参数..."); schoolDetails = await schoolDetailsTask; var parameter = await loginWorker.GetLoginParameter(Username, Password, schoolDetails.GetIdsLoginUrl()); if (parameter.NeedCaptcha) { Log.Information("需要验证码!"); throw new Exception("需要验证码!暂时无法处理!"); } Log.Information("正在登录..."); cookies = await loginWorker.IdsLogin(parameter); Log.Information("登录成功, Cookie: {cookie}", cookies); // remove before adding to avoid duplication. AppConfig.Users.RemoveAll(x => x.Username == Username); AppConfig.Users.Add(new User() { Username = Username, Password = Password }); SaveAppConfig(); } catch (Exception ex) { Log.Error("登录过程中出现异常!"); Log.Error(ex.Message); Log.Error(ex.StackTrace); return(1); } return(await base.OnExecuteAsync(app)); }
public bool Put(SchoolDetails schoolDetails) { SchoolDetailsRepository school = new SchoolDetailsRepository(); return(school.Put(schoolDetails)); }
protected async override Task <int> OnExecuteAsync(CommandLineApplication app) { Log.Information("User: {username}", Username); Log.Information("School: {school}", SchoolName); CpdailyCore cpdaily = new CpdailyCore(); string cookies = null; SchoolDetails schoolDetails = null; try { Log.Information("正在获取 {info} ...", "SecretKey"); var secretKeyTask = cpdaily.GetSecretKeyAsync(); Log.Information("正在获取 {info} ...", "学校列表"); var schools = await cpdaily.GetSchoolsAsync(); Log.Information("正在获取 {info} ...", "学校ID"); var school = schools.Where(x => x.Name == SchoolName).FirstOrDefault(); var schoolDetailsTask = cpdaily.GetSchoolDetailsAsync(school, await secretKeyTask); Type loginWorkerType = Utils.GetLoginWorkerByName(SchoolName); ILoginWorker loginWorker = null; if (loginWorkerType != null) { Log.Information("使用专门登录适配器 <{LoginWorkerTypeName}>", loginWorkerType.Name); loginWorker = (ILoginWorker)Activator.CreateInstance(loginWorkerType); } else { Log.Information("使用通用登录适配器 <{LoginWorkerTypeName}>", "DefaultLoginWorker"); loginWorker = new DefaultLoginWorker(); } Log.Information("正在获取登录所需参数..."); schoolDetails = await schoolDetailsTask; var parameter = await loginWorker.GetLoginParameter(Username, Password, schoolDetails.GetIdsLoginUrl()); if (parameter.NeedCaptcha) { Log.Information("需要验证码!"); throw new Exception("需要验证码!暂时无法处理!"); } Log.Information("正在登录..."); cookies = await loginWorker.IdsLogin(parameter); Log.Information("登录成功, Cookie: {cookie}", cookies); // remove before adding to avoid duplication. AppConfig.Users.RemoveAll(x => x.Username == Username); AppConfig.Users.Add(new User() { Username = Username, Password = Password }); AppConfig.SchoolName = SchoolName; SaveAppConfig(); } catch (Exception ex) { Log.Error("登录过程中出现异常!"); Log.Error(ex.Message); Log.Error(ex.StackTrace); return(1); } try { Log.Warning("下面进行表单向导,模拟完成一次历史表单,让程序学习如何填写表单。"); Log.Information("获取历史表单..."); var forms = await cpdaily.GetFormItemsHistoryAsync(schoolDetails.GetAmpUrl(), cookies); if (forms.Length == 0) { throw new Exception("没有获取到历史表单,表单向导无法继续!"); } Log.Information("获取到 {count} 条历史表单记录,请选择其中一条(输入序号):", forms.Length); for (int i = 0; i < forms.Length; i++) { Log.Information("{No}. {Title}", i + 1, forms[i].Title); } int index = Convert.ToInt32(Console.ReadLine()) - 1; FormItem form = forms[index]; var formFields = await cpdaily.GetFormFieldsAsync(schoolDetails.GetAmpUrl(), cookies, form.WId, form.FormWId); var requiredFields = formFields.Where(x => x.IsRequired == true).ToArray(); Log.Information("获取到 {count} 条必填字段", requiredFields.Length); List <FormFieldChange> result = new List <FormFieldChange>(); for (int i = 0; i < requiredFields.Length; i++) { FormField field = requiredFields[i]; var typeString = field.FieldType switch { 1 => "填空", 2 => "单选", 3 => "多选", 4 => "图片", _ => "未知", }; Log.Information("{No}. {Title} ({type}):", i + 1, field.Title, typeString); Log.Information("描述: {Description}", string.IsNullOrEmpty(field.Description) ? "无" : field.Description); if (field.FieldType == 1) { Log.Information("请输入文本:"); string value = Console.ReadLine(); var c = new FormFieldChange() { FieldType = field.FieldType, Title = field.Title, Value = value }; result.Add(c); } else if (field.FieldType == 2) { for (int t = 0; t < field.FieldItems.Count; t++) { FieldItem item = field.FieldItems[t]; Log.Information("\t{No}.{Title}", t + 1, item.Content); } Log.Information("请输入选项序号:"); int value = Convert.ToInt32(Console.ReadLine()) - 1; var c = new FormFieldChange() { FieldType = field.FieldType, Title = field.Title, Value = field.FieldItems[value].Content }; result.Add(c); } else { throw new Exception("暂不支持这种类型,请到 Github 提出 issues!"); } } Log.Information("表单向导完成!"); AppConfig.FormFields = result; SaveAppConfig(); } catch (Exception ex) { Log.Error("表单向导过程中出现异常!"); Log.Error(ex.Message); Log.Error(ex.StackTrace); return(1); } return(await base.OnExecuteAsync(app)); }
protected async override Task <int> OnExecuteAsync(CommandLineApplication app) { if (AppConfig.Users.Count == 0) { Log.Error("没有找到任何用户,请执行 init 指令初始化配置文件。"); return(1); } if (string.IsNullOrEmpty(AppConfig.SchoolName)) { Log.Error("学校名称字段不可为空!请检查配置文件或执行 init 指令初始化配置文件!"); return(1); } if (AppConfig.FormFields.Count == 0) { Log.Error("没有找到任何表单字段!请检查配置文件或执行 init 指令初始化配置文件!"); return(1); } CpdailyCore cpdaily = new CpdailyCore(); string SchoolName = AppConfig.SchoolName; SchoolDetails schoolDetails = null; ILoginWorker loginWorker = null; try { Log.Information("正在获取 {info} ...", "SecretKey"); var secretKeyTask = cpdaily.GetSecretKeyAsync(); Log.Information("正在获取 {info} ...", "学校列表"); var schools = await cpdaily.GetSchoolsAsync(); Log.Information("正在获取 {info} ...", "学校ID"); var school = schools.Where(x => x.Name == SchoolName).FirstOrDefault(); schoolDetails = await cpdaily.GetSchoolDetailsAsync(school, await secretKeyTask); Type loginWorkerType = Utils.GetLoginWorkerByName(SchoolName); if (loginWorkerType != null) { Log.Information("使用专门登录适配器 <{LoginWorkerTypeName}>", loginWorkerType.Name); loginWorker = (ILoginWorker)Activator.CreateInstance(loginWorkerType); } else { Log.Information("使用通用登录适配器 <{LoginWorkerTypeName}>", "DefaultLoginWorker"); loginWorker = new DefaultLoginWorker(); } } catch (Exception ex) { Log.Error("获取基本参数时出现异常!"); Log.Error(ex.Message); Log.Error(ex.StackTrace); return(1); } for (int i = 0; i < AppConfig.Users.Count; i++) { string Username = AppConfig.Users[i].Username; string Password = AppConfig.Users[i].Password; string cookies = null; try { Log.Information("正在登录 {username} ...", Username); Log.Information("正在获取登录所需参数..."); var parameter = await loginWorker.GetLoginParameter(Username, Password, schoolDetails.GetIdsLoginUrl()); if (parameter.NeedCaptcha) { Log.Information("需要验证码!"); throw new Exception("需要验证码!暂时无法处理!"); } Log.Information("正在登录..."); cookies = await loginWorker.IdsLogin(parameter); Log.Information("登录成功, Cookie: {cookie}", cookies); } catch (Exception ex) { Log.Error("登录过程中出现异常!"); Log.Error(ex.Message); Log.Error(ex.StackTrace); } try { var formItems = await cpdaily.GetFormItemsAsync(schoolDetails.GetAmpUrl(), cookies); Log.Information("找到了 {count} 个未填表单!", formItems.Length); foreach (var form in formItems) { Log.Information("正在获取表单的字段..."); var formFields = await cpdaily.GetFormFieldsAsync(schoolDetails.GetAmpUrl(), cookies, form.WId, form.FormWId); var requiredFields = formFields.Where(x => x.IsRequired == true).ToArray(); if (requiredFields.Length != AppConfig.FormFields.Count) { var desc = $"配置文件中的表单字段数量({AppConfig.FormFields.Count})与需要的表单字段数量({requiredFields.Length})不一样!"; throw new Exception(desc); } for (int t = 0; t < requiredFields.Length; ++t) { requiredFields[t] = CpdailyCore.MergeToFormField(requiredFields[t], AppConfig.FormFields[t]); } Log.Information("提交表单中..."); await cpdaily.SubmitForm(schoolDetails.GetAmpUrl(), cookies, form, requiredFields, AppConfig.Address, AppConfig.Latitude, AppConfig.Longitude); Log.Information("表单提交成功!"); } } catch (Exception ex) { Log.Error("提交表单时出现异常!"); Log.Error(ex.Message); Log.Error(ex.StackTrace); } } return(await base.OnExecuteAsync(app)); }