internal void Sync() { var person = Data.Submitter.GetRockPerson(); if (person == null) { throw new Exception("Could not find Rock person for Rise Id: " + Data.Submitter.Id); } RiseClient riseClient = new RiseClient(); var course = riseClient.SyncCourse(Data.Course); RockContext rockContext = new RockContext(); ExperienceService experienceService = new ExperienceService(rockContext); var experience = new Experience { PersonAliasId = person.PrimaryAliasId ?? 0, VerbValueId = xAPI.Utilities.VerbHelper.GetOrCreateVerb("http://activitystrea.ms/schema/1.0/author").Id, xObject = new ExperienceObject { EntityTypeId = EntityTypeCache.Get(typeof(Course)).Id, ObjectId = course.Id.ToString() }, Result = new ExperienceResult { IsComplete = true, WasSuccess = true } }; experienceService.Add(experience); rockContext.SaveChanges(); }
internal void SaveUserCreated(Person person) { RockContext rockContext = new RockContext(); ExperienceService experienceService = new ExperienceService(rockContext); var verb = xAPI.Utilities.VerbHelper.GetOrCreateVerb("http://activitystrea.ms/schema/1.0/join"); var experience = new Experience { PersonAliasId = person.PrimaryAliasId ?? 0, VerbValueId = verb.Id, xObject = new ExperienceObject { EntityTypeId = EntityTypeCache.Get(typeof(xAPIComponent)).Id, ObjectId = EntityTypeCache.Get(typeof(RiseComponent)).Id.ToString() }, Result = new ExperienceResult { WasSuccess = true, IsComplete = true } }; experienceService.Add(experience); rockContext.SaveChanges(); var context = experience.AddQualifier("context"); var experiences = context.AddQualifier("experiences"); experiences.AddQualifier( xAPI.Utilities.ExtensionHelper.GetOrCreateExtension("http://id.tincanapi.com/extension/datetime"), RockDateTime.Now.ToString()); }
public static void UpdateCourseStatus(ExperienceObject xObject, Person person, bool complete, int?quizScorePercent, Dictionary <string, string> contextExtensions) { RockContext rockContext = new RockContext(); ExperienceService experienceService = new ExperienceService(rockContext); ExperienceQualifierService experienceQualifierService = new ExperienceQualifierService(rockContext); var experience = experienceService.Queryable() .Where(e => e.PersonAlias.PersonId == person.Id && e.xObjectId == xObject.Id) .FirstOrDefault(); if (experience == null) { experience = new Experience { PersonAliasId = person.PrimaryAliasId ?? 0, VerbValueId = xAPI.Utilities.VerbHelper.GetOrCreateVerb("http://activitystrea.ms/schema/1.0/complete").Id, xObjectId = xObject.Id, Result = new ExperienceResult { IsComplete = complete, WasSuccess = complete } }; experienceService.Add(experience); } else { experience.Result.IsComplete = complete; experience.Result.WasSuccess = complete; } rockContext.SaveChanges(); if (quizScorePercent.HasValue) { var score = experience.Result.AddQualifier("score"); score.AddQualifier("percent", quizScorePercent.Value.ToString()); } var context = experience.AddQualifier("context"); var extensions = context.AddQualifier("extensions"); foreach (var extension in contextExtensions) { extensions.AddQualifier(extension.Key, extension.Value); } }
public ActionResult EditSave(Employee employee) { if (employee.Name == null) { return(Content("请输入姓名!")); } if (employee.nl == 0) { return(Content("请输入年龄!")); } if (employee.xb == null) { return(Content("请选择性别!")); } string strZp = Request.Form["strZp"].ToString(); string strSfzt = Request.Form["strSfzt"].ToString(); HttpFileCollectionBase files = Request.Files; HttpPostedFileBase FileSfzt = files["sfzt"]; string FileName = FileSfzt.FileName; //上传的原文件名 if (FileName != "") //换了图片 { string guidSfzt = ""; if (FileName != null && FileName != "") { string FileType = FileName.Substring(FileName.LastIndexOf(".") + 1); //得到文件的后缀名 guidSfzt = employee.Code + "-SFZ-" + System.Guid.NewGuid().ToString() + "." + FileType; //得到重命名的文件名 FileSfzt.SaveAs(Server.MapPath("/Upload/") + guidSfzt); //保存操作 } employee.sfzt = guidSfzt; } else { employee.sfzt = strSfzt; } HttpPostedFileBase FileZp = files["Zp"]; string FileNameZp = FileZp.FileName; //上传的原文件名 if (FileNameZp != "") //换了图片 { string guidZp = ""; if (FileNameZp != null && FileNameZp != "") { string FileType = FileNameZp.Substring(FileNameZp.LastIndexOf(".") + 1); //得到文件的后缀名 guidZp = employee.Code + "-ZP-" + System.Guid.NewGuid().ToString() + "." + FileType; //得到重命名的文件名 FileZp.SaveAs(Server.MapPath("/Upload/") + guidZp); //保存操作 } employee.zp = guidZp; } else { employee.zp = strZp; } string jtStr = Request.Form["jtStr"].ToString(); string gzStr = Request.Form["gzStr"].ToString(); string pxStr = Request.Form["pxStr"].ToString(); JavaScriptSerializer js = new JavaScriptSerializer(); //处理家庭成员 int jtCount = FamilyService.GetRecordCoutn(u => u.EmployeeID == employee.ID); List <Family> listJt = js.Deserialize <List <Family> >(jtStr); for (int j = 0; j < listJt.Count; j++) { Family family1 = listJt[j]; family1.Employee = employee; family1.EmployeeID = employee.ID; family1.ModifiedBy = LoginUserInfo == null ? 0 : LoginUserInfo.ID; family1.ModifiedTIme = DateTime.Now; if (family1.Code == null) { family1 = initFamily(family1); family1.Code = employee.Code + "-F" + (jtCount + 1).ToString(); FamilyService.Add(family1); } else { family1.ModifiedBy = LoginUserInfo == null ? 0 : LoginUserInfo.ID; family1.ModifiedTIme = DateTime.Now; FamilyService.Update(family1); } } FamilyService.SaveChanges(); //处理工作经历 int gzCount = ExperienceService.GetRecordCoutn(u => u.EmployeeID == employee.ID); List <Experience> listGz = js.Deserialize <List <Experience> >(gzStr); for (int i = 0; i < listGz.Count; i++) { Experience experience = listGz[i]; experience.Employee = employee; experience.EmployeeID = employee.ID; experience.ModifiedBy = LoginUserInfo == null ? 0 : LoginUserInfo.ID; experience.ModifiedTIme = DateTime.Now; if (experience.Code == null) { experience = initExperience(experience); experience.Code = employee.Code + "-E" + (gzCount + 1).ToString(); ExperienceService.Add(experience); } else { experience.ModifiedBy = LoginUserInfo == null ? 0 : LoginUserInfo.ID; experience.ModifiedTIme = DateTime.Now; ExperienceService.Update(experience); } } //处理培训经历 int pxCount = TrainService.GetRecordCoutn(u => u.EmployeeID == employee.ID); List <Train> listPx = js.Deserialize <List <Train> >(pxStr); for (int i = 0; i < listPx.Count; i++) { Train train = listPx[i]; train.Employee = employee; train.EmployeeID = employee.ID; train.ModifiedBy = LoginUserInfo == null ? 0 : LoginUserInfo.ID; train.ModifiedTIme = DateTime.Now; if (train.Code == null) { train = initTrain(train); train.Code = employee.Code + "-T" + (pxCount + 1).ToString(); TrainService.Add(train); } else { train.ModifiedBy = LoginUserInfo == null ? 0 : LoginUserInfo.ID; train.ModifiedTIme = DateTime.Now; TrainService.Update(train); } } employee.ModifiedBy = LoginUserInfo == null ? 0 : LoginUserInfo.ID; employee.ModifiedTIme = DateTime.Now; if (EmployeeService.Update(employee)) { TrainService.SaveChanges(); ExperienceService.SaveChanges(); FamilyService.SaveChanges(); EmployeeService.SaveChanges(); return(Content("ok")); } return(Content("修改失败了!")); }