private static void setColectorHits(List<Collector> collectors) { var cr = new CollectorsHits {Collectors = collectors}; var orm = new Orm(); log.Info("Writting information to database - number of hits"); var res = orm.execObject<Ranking.DataAccess.Result>(cr, "api.set_collectors_rank"); }
public void process() { try { log.Info("debugging in here"); var collectors = new CollectorRun().collectors; foreach (var c in collectors) { log.Info("processing " + c.firstName + " " + c.lastName); new AssignRanking(c).assign(); new AssignCompletion(c).assign(); log.Info("finsihed calculation for " + c.firstName + " " + c.lastName); } var orm = new Orm(); log.Info("trying to save ranking and completion for all"); var result = orm.execObject<Result>(collectors, "job.collector_ranking_completion_set"); log.Info("sucessfuly saved ranking and completion for all"); } catch(Exception exp) { log.Error(exp); } }
private Globals() { var orm = new Orm(); var result = orm.execObject<Ranking.DataAccess.Result>(null, "api.global_config"); getSettings(result.Global); getRankPages(result.Global); }
public void enqueueMessage(ITemplate template) { var message = buildMessage(template); var data = new MSSQLData(Globals.Instance.settings["MessagingConnection"]); var orm = new Orm(data); var res = orm.execObject<Result>(message, "mess.enqueue_message"); }
internal static List<Message> fetch() { var connstr = Config.Instance.dbConn; var orm = new Orm(new MSSQLData(connstr)); var dbMails = orm.execObject<Result>(null, "mess.dequeue_message").Message; return dbMails; }
private Collectors Collectors() { log.Info("fetching all collectors from db"); var orm = new Orm(); var result = orm.execObject<Result>(null, "job.collector_all"); log.Info("fetched all collectors from db"); return result.Collectors; }
public static IMappingGenerator GetMapGenerator(Orm codeForOrm) { switch (SessionInfo.Instance.OrmCodeGeneration) { case Orm.NHibernate: return new NHibernateMappingGen(); default: throw new Exception("Unrecognized ORM for mapping generation."); } }
private void DefaultConfig() { GenerateDBMSOutput = false; OrmCodeGeneration = Orm.NHibernate; SaveAction = SaveAction.Overwrite; FileSaveMode = SaveMode.DistinctFile; SaveFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory) + "\\Code"; MapGenSettings = new MapGenSettings { GenereteDomainEqualityComparer = false, GeneretePartialDomain = false, }; }
public static IEnumerable<Message> Messages() { var messages = new List<Message>(); var result = new Result(); var orm = new Orm(new MSSQLData()); log.Info("getting messages from db"); result = orm.execObject<Result>(null, "mess.dequeue_message"); if (result.Message != null) { messages.AddRange(result.Message); } return messages; }
public static void SendMessages(IEnumerable<Message> messages) { var orm = new Orm(new MSSQLData()); foreach (var m in messages) { var messageStatus = new MessageStatus { Message = m }; if (m.type == "FACEBOOK") messageStatus.status = (FacebookPost(m) == true) ? "SENT" : "FAILED"; if (m.type == "EMAIL") messageStatus.status = (JangoEmail(m) == true) ? "SENT" : "FAILED"; orm.execObject<Result>(messageStatus, "mess.set_message_status"); } }
public static void save(PaymentNotice paymentNotice) { try { var orm = new Orm(); var result = orm.execObject<Result>(paymentNotice, "api.user_add_payment_notice"); if (result.errorMessage != null) throw new DivideByZeroException(); } catch (DivideByZeroException exp) { log.Error("Error saving payment notice to DB" + exp.Message); throw; } }
public PaymentStatus makePayment() { var orm = new Orm(); var result = orm.execObject<Result>(payment, "api.user_payment_create"); if (result.errorMessage == null && result.dbMessage == null) { payment.paymentRef = result.Payment.paymentRef; payment.shopperEmail = result.Payment.shopperEmail; payment.shopperRef = result.Payment.shopperRef; payment.amount = result.Payment.amount; payment.currency = result.Payment.currency; payment.saveDetails = true; return new ProcessPayment(payment).pay(); } return new PaymentStatus() {success = false, message = "PAYMENT_FAILED"}; }
/// <summary> /// 学生开课数据录入 /// </summary> /// <param name="request"></param> /// <returns></returns> public bool AddOrderStudent(OrderModel model, int System_Station_ID, string StuId) { bool flag = false; string stuID = string.IsNullOrEmpty(StuId) ? model.StuId : StuId; Random ran = new Random(); model.AddTime = DateTime.Now; model.PayTime = DateTime.Now; model.OrderNo = DateTime.Now.ToString("yyyyMMddHHmmss") + ran.Next(1000, 9999).ToString(); model.StuId = stuID; model.System_Station_ID = System_Station_ID; model.OrderId = Guid.NewGuid().ToString("N").ToUpper(); if (!string.IsNullOrWhiteSpace(model.Course_IDs)) { W_Order order = new W_Order(); order.StuId = model.StuId; order.OrderNo = model.OrderNo; order.System_Station_ID = model.System_Station_ID; order.AddTime = model.AddTime; order.Price = model.Price; order.PayStatus = model.PayStatus; order.PayType = model.PayType; order.PayTime = model.PayTime; order.PayPrice = model.PayPrice; order.TicketNumber = model.TicketNumber; order.OrderState = model.OrderState; order.OrderId = model.OrderId; try { SqlMapper.BeginTransaction();//开启事务 //添加订单 int id = (int)Orm.Insert(order, true); if (id > 0) { string[] c_id = model.Course_IDs.Split(','); string[] c_price = model.Prices.Split(','); for (int i = 0; i < c_id.Length; i++) { W_Order_Detail orderdetail = new W_Order_Detail(); orderdetail.CID = id; orderdetail.Course_ID = int.Parse(c_id[i]); orderdetail.Price = decimal.Parse(c_price[i]); //添加订单详细 Orm.Insert(orderdetail); } flag = true; } SqlMapper.CommitTransaction(); //提交 } catch (Exception ex) { SqlMapper.RollBackTransaction(); //回滚 throw new ApiException(ex.Message); } finally { //SqlMapper.CloseConnection(); } } return(flag); }
public void Orm_ShouldcreateValidSql_Select_NoTable() { var sql = new Orm().Select("abc").BuildQuery(); Assert.AreEqual("SELECT abc", sql.Sql); }
public void Orm_ShouldcreateValidSql_SkipNTakeN() { var sql = new Orm().From("table").Where(new Where("columnName", "abc")).Take(2).Skip(2).BuildQuery(); Assert.AreEqual("SELECT * FROM table WHERE columnName = @param0 ORDER BY(SELECT NULL) OFFSET 2 ROWS FETCH NEXT 2 ROWS ONLY", sql.Sql); }
public void Orm_ShouldcreateValidSql_TakeN() { var sql = new Orm().From("table").Where(new Where("columnName", "abc")).Take(2).BuildQuery(); Assert.AreEqual("SELECT TOP 2 * FROM table WHERE columnName = @param0", sql.Sql); }
public void assignServices() { var orm = new Orm(); orm.execObject <Result>(round, "api.round_assign_services"); }
/// <summary> /// 删除单体异步 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <returns></returns> public Task <int> UowDeleteAsync <T>(T entity) where T : class { return(Orm.Delete <T>(entity).WithTransaction(UnitOfWork.GetOrBeginTransaction()).ExecuteAffrowsAsync()); }
/// <summary> /// 显示做题结果 /// </summary> /// <param name="busId"></param> /// <param name="resultId"></param> /// <param name="stuId"></param> /// <returns></returns> public dynamic GetPracticeResult(int busId, int resultId, string stuId) { ExamResults Results = new ExamResults(); Results.List = new List <Question>(); Results.List = SqlMapper.QueryForList <Question>("GetPracticeResult", new { busId, resultId, stuId }).OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); W_DoExamResult theResult = Orm.Single <W_DoExamResult>(x => x.ID == resultId); Results.TotalTime = theResult != null ? (theResult.EndTime - theResult.BeginTime).TotalSeconds : 0.00; if (Results.List.Count > 0) { List <ResultSummary> list = new List <ResultSummary>(); List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == stuId).ToList();//题目笔记列表 foreach (Question q in Results.List) { ResultSummary temp = list.FirstOrDefault(x => x.TypeID == q.QuestionType_ID); if (temp == null) { temp = new ResultSummary(); temp.TypeID = q.QuestionType_ID; temp.TypeName = q.QuestionType_Name; temp.TotalCounts = 1; if (!string.IsNullOrEmpty(q.MyAnswer)) { temp.AlreadyCounts = 1; if (q.Judge == 1) { temp.CorrectCounts = 1; } else { temp.ErrorCounts = 1; } } temp.YetCounts = temp.TotalCounts - temp.AlreadyCounts; temp.CorrectRate = ((float)temp.CorrectCounts / temp.TotalCounts * 100).ToString("f2"); list.Add(temp); } else { temp.TypeID = q.QuestionType_ID; temp.TypeName = q.QuestionType_Name; temp.TotalCounts += 1; if (!string.IsNullOrEmpty(q.MyAnswer)) { temp.AlreadyCounts += 1; if (q.Judge == 1) { temp.CorrectCounts += 1; } else { temp.ErrorCounts += 1; } } temp.YetCounts = temp.TotalCounts - temp.AlreadyCounts; temp.CorrectRate = ((float)temp.CorrectCounts / temp.TotalCounts * 100).ToString("f2"); } q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } Results.Result = list; } return(Results); }
/// <summary> /// 修改题库信息 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool UpdateQuestionStore(W_QuestionStore model) { return(Orm.Update(model) > 0); }
/// <summary> /// Excel转Question /// </summary> /// <param name="intputStream"></param> /// <param name="FileName"></param> /// <param name="System_Station_ID"></param> /// <returns></returns> public dynamic ExcelToQuestionList(System.IO.Stream intputStream, string FileName, int System_Station_ID) { IWorkbook workbook = null; try { if (FileName.EndsWith(".xlsx")) // 2007版本 { workbook = new XSSFWorkbook(intputStream); } else if (FileName.EndsWith(".xls")) // 2003版本 { workbook = new HSSFWorkbook(intputStream); } } catch (Exception ex) { throw new ApiException("上传异常,异常原因:" + ex.Message + "<br/>请尝试参考导入模板格式进行导入。"); } ISheet sheet = workbook.GetSheetAt(0); List <Question> list = new List <Question>(); Question question = null; List <W_QuestionStore> storeList = Orm.Select <W_QuestionStore>(x => x.System_Station_ID == System_Station_ID);//题库 /*Excel模板从第四行开始 * 第一列为题库 * 第二列为试题类型 * 第三列为试题难度 * 第四列为试题内容 * 第五列为试题答案 * 第六至第十三列为选择题选项 * 第十四列为答案解析 */ for (int i = 4; i <= sheet.LastRowNum; i++) { var row = sheet.GetRow(i); if (row == null) { continue; } ; List <W_QuestionStore> sList = storeList.Where(x => x.Name == GetCellValue(row.GetCell(0)) && x.IsDelete == 0).ToList(); if (sList.Count > 0)//可能存在多个题库 { try { foreach (var item in sList) { question = new Question(); if (sList.Count > 1) { question.MyAnswer = "MoreStore"; } else { question.MyAnswer = "Normal"; } question.QuestionStore_ID = item.ID; question.QuestionStore_Name = item.Name; question.QuestionType_ID = int.Parse(GetCellValue(row.GetCell(1))); if (question.QuestionType_ID > 6 || question.QuestionType_ID < 1) { throw new Exception(); } question.Level = int.Parse(GetCellValue(row.GetCell(2))); question.Title = GetCellValue(row.GetCell(3)); question.Answer = GetCellValue(row.GetCell(4)); question.Mark = GetCellValue(row.GetCell(13)); var dictionary = new Dictionary <string, object>(); if (question.QuestionType_ID <= 2) { if (!string.IsNullOrEmpty(GetCellValue(row.GetCell(5)))) { dictionary.Add("A", GetCellValue(row.GetCell(5))); question.AnswerCount++; } if (!string.IsNullOrEmpty(GetCellValue(row.GetCell(6)))) { dictionary.Add("B", GetCellValue(row.GetCell(6))); question.AnswerCount++; } if (!string.IsNullOrEmpty(GetCellValue(row.GetCell(7)))) { dictionary.Add("C", GetCellValue(row.GetCell(7))); question.AnswerCount++; } if (!string.IsNullOrEmpty(GetCellValue(row.GetCell(8)))) { dictionary.Add("D", GetCellValue(row.GetCell(8))); question.AnswerCount++; } if (!string.IsNullOrEmpty(GetCellValue(row.GetCell(9)))) { dictionary.Add("E", GetCellValue(row.GetCell(9))); question.AnswerCount++; } if (!string.IsNullOrEmpty(GetCellValue(row.GetCell(10)))) { dictionary.Add("F", GetCellValue(row.GetCell(10))); question.AnswerCount++; } if (!string.IsNullOrEmpty(GetCellValue(row.GetCell(11)))) { dictionary.Add("G", GetCellValue(row.GetCell(11))); question.AnswerCount++; } if (!string.IsNullOrEmpty(GetCellValue(row.GetCell(12)))) { dictionary.Add("H", GetCellValue(row.GetCell(12))); question.AnswerCount++; } question.Body = new JavaScriptSerializer().Serialize(dictionary); } list.Add(question); } } catch { question = new Question(); question.MyAnswer = "TextError"; list.Add(question); continue; } } else { question = new Question(); question.MyAnswer = "NoStore"; list.Add(question); } } return(list); }
/// <summary> /// 添加纠错 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool AddQuestionerrorCorrection(W_QuestionerrorCorrection model) { return(Orm.Insert(model) > 0); }
/// <summary> /// 添加组合题材料 /// </summary> /// <param name="model"></param> /// <returns></returns> public int AddQuestionData(W_QuestionData model) { return((int)Orm.Insert(model, true)); }
public WeaponCharter(Orm orm) : base(orm) { }
public BaseController() { result = new Result(); orm = new Orm(); }
private Globals() { var orm = new Orm(); var result = orm.execObject<Result>(null, "api.global_config"); getSettings(result.Global); }
internal static void save(Message message) { var orm = new Orm(); orm.execObject<Result>(message, "mess.enqueue_message"); }
/// <summary> /// 继续做题 做题记录页面进来,继续/重新做题 继续做题:继续原来未完成的做题记录 重新做题:开始新的做题记录,题目和原做题记录题目一致(刷新页面确保逻辑一致) /// </summary> /// <param name="ID"></param> /// <param name="stuId"></param> /// <returns></returns> public dynamic ContinueChapterPractice(int ID, string stuId) { PracticeModel rtn = new PracticeModel(); W_ChapterPractice cp = Orm.Single <W_ChapterPractice>(x => x.ID == ID); if (cp == null) { throw new ApiException("练习记录不存在或已删除"); } rtn.practiceId = cp.ID; W_DoExamResult result = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp.ID); List <Question> list = SqlMapper.QueryForList <Question>("GetChapterPracticeDetailQuestion", new { chapterPracticeID = cp.ID, stuId = stuId }).ToList(); List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == stuId).ToList(); //题目笔记列表 if (result.Valid == 1) //重新做题 { W_ChapterPractice cp2 = Orm.Single <W_ChapterPractice>(x => x.Source == cp.Source && x.Status == 0); //重新做题页面刷新 if (cp2 == null) { string[] str = cp.Source.Split('_'); if (str.Length != 6) { throw new ApiException("练习记录数据有误"); } W_ChapterPractice model = new W_ChapterPractice(); model.QuestionStore_ID = int.Parse(str[0]); model.AddTime = DateTime.Now; model.StuId = stuId; //第一步,创建章节练习表W_ChapterPractice W_Chapter chapter = Orm.Select <W_Chapter>(x => x.ID.ToString() == str[1]).FirstOrDefault(); model.Title = chapter != null ? chapter.Name + "章节练习" + model.AddTime.ToString("yyyyMMddHHmmssfff") : "未知章节练习"; model.Source = cp.Source; int practiceId = (int)Orm.Insert <W_ChapterPractice>(model, true); //第二步,创建明细表w_chapterpractice_detail foreach (Question q in list) { Orm.Insert <W_ChapterPractice_Detail>(new W_ChapterPractice_Detail() { ChapterPractice_ID = practiceId, Question_ID = q.ID }); q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } // 第三步,创建学生做题记录主表,保存开始做题时间 W_DoExamResult res = new W_DoExamResult(); res.StuId = model.StuId; res.BusType = 1;//章节练习 res.BusID = practiceId; res.BeginTime = model.AddTime; res.EndTime = model.AddTime; int resultId = (int)Orm.Insert <W_DoExamResult>(res, true); rtn.practiceId = practiceId; rtn.resultId = resultId; rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); } else { W_DoExamResult result2 = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp2.ID); if (result == null) { throw new ApiException("练习记录不存在或已删除"); } rtn.resultId = result2.ID; foreach (Question q in list) { q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); //更新做题记录时间 result2.BeginTime = DateTime.Now; Orm.Update <W_DoExamResult>(result2); } } else { if (result == null) { throw new ApiException("练习记录不存在或已删除"); } rtn.resultId = result.ID; foreach (Question q in list) { q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); //更新做题记录时间 result.BeginTime = DateTime.Now; Orm.Update <W_DoExamResult>(result); } return(rtn); }
public bool Exists(int?personId, int?roleId, int?schoolId) { return(Exists(Orm.SimpleSelect <SchoolPerson>(GetSchoolPersonsCondition(personId, roleId, schoolId)))); }
static void TrackToList(object list) { if (list is null) { return; } if (list is not IList <TEntity> ls) { if (list is not IEnumerable ie) { return; } var isFirst = true; IBaseRepository <TEntity> baseRepo = null; foreach (var item in ie) { if (item is null) { return; } if (isFirst) { isFirst = false; var itemType = item.GetType(); if (itemType == typeof(object)) { return; } if (itemType.FullName !.Contains("FreeSqlLazyEntity__")) { itemType = itemType.BaseType; } if (Orm.CodeFirst.GetTableByEntity(itemType)?.Primarys.Any() != true) { return; } if (item is not BaseEntity <TEntity> ) { return; } } if (item is BaseEntity <TEntity> entity) { baseRepo ??= Orm.GetRepository <TEntity>(); entity.Repository = baseRepo; entity.Attach(); } } return; } if (ls.Any() == false) { return; } if (ls.FirstOrDefault() is not BaseEntity <TEntity> ) { return; } if (Orm.CodeFirst.GetTableByEntity(typeof(TEntity))?.Primarys.Any() != true) { return; } IBaseRepository <TEntity> repo = null; foreach (var item in ls) { if (item is BaseEntity <TEntity> entity) { repo ??= Orm.GetRepository <TEntity>(); entity.Repository = repo; entity.Attach(); } } }
/// <summary> /// Determines whether the given expression can be represented as a column in a select expressionss /// </summary> /// <param name="expression"></param> /// <returns></returns> private bool CanBeColumn(Expression expression) { switch (expression.NodeType) { case ExpressionType.Add: case ExpressionType.AddChecked: case ExpressionType.Subtract: case ExpressionType.SubtractChecked: case ExpressionType.Multiply: case ExpressionType.MultiplyChecked: case ExpressionType.Divide: case ExpressionType.Modulo: case ExpressionType.And: case ExpressionType.AndAlso: case ExpressionType.Or: case ExpressionType.OrElse: case ExpressionType.ExclusiveOr: case ExpressionType.OnesComplement: case ExpressionType.Not: case ExpressionType.Negate: case ExpressionType.NegateChecked: case ExpressionType.UnaryPlus: case ExpressionType.RightShift: case ExpressionType.LeftShift: case ExpressionType.Equal: case ExpressionType.NotEqual: case ExpressionType.GreaterThan: case ExpressionType.GreaterThanOrEqual: case ExpressionType.LessThan: case ExpressionType.LessThanOrEqual: case ExpressionType.Coalesce: return(true); case ExpressionType.Constant: return(Orm.IsColumnTypeSupported(expression.Type)); case ExpressionType.Convert: case ExpressionType.ConvertChecked: return(true); case ExpressionType.Conditional: return(true); case ExpressionType.Call: Type declaringType = ((MethodCallExpression)expression).Method.DeclaringType; if (declaringType == typeof(DateTime) || declaringType == typeof(DateTimeOffset) || declaringType == typeof(TimeSpan) || declaringType == typeof(string) || declaringType == typeof(decimal) || declaringType == typeof(Math)) { return(true); } goto default; case ExpressionType.MemberAccess: Type mDeclaringType = ((MemberExpression)expression).Member.DeclaringType; if (mDeclaringType == typeof(DateTime) || mDeclaringType == typeof(DateTimeOffset) || mDeclaringType == typeof(TimeSpan) || mDeclaringType == typeof(string)) { return(true); } goto default; default: return(MustBeColumn(expression)); } }
/// <summary> /// 创建章节练习 /// </summary> /// <param name="model"></param> /// <returns></returns> public PracticeModel CreateChapterPractice(W_ChapterPractice model, int chapterId, string questionType, int questionCount, int questionSource) { PracticeModel rtn = new PracticeModel(); List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == model.StuId).ToList();//题目笔记列表 //判断是重新生成章节练习还是继续之前的章节练习 W_ChapterPractice cp = Orm.Single <W_ChapterPractice>(x => x.Source == model.QuestionStore_ID + "_" + chapterId + "_" + questionType + "_" + questionCount + "_" + questionSource + "_" + model.StuId && x.Status == 0); if (cp != null)//继续做题 { rtn.practiceId = cp.ID; W_DoExamResult result = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp.ID); if (result == null) { throw new ApiException("练习有误,请刷新重试"); } rtn.resultId = result.ID; List <Question> list = SqlMapper.QueryForList <Question>("GetChapterPracticeDetailQuestion", new { chapterPracticeID = cp.ID, stuId = model.StuId }).ToList(); foreach (Question q in list) { q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); //更新做题记录时间 result.BeginTime = model.AddTime; Orm.Update <W_DoExamResult>(result); } else//重新生成 { List <Question> list = SqlMapper.QueryForList <Question>("GetChapterPracticeQuestion", new { chapterId, questionType, questionCount, questionSource, stuId = model.StuId }).ToList(); if (list.Count == 0) { throw new ApiException("没有更多的试题"); } //第一步,创建章节练习表W_ChapterPractice W_Chapter chapter = Orm.Select <W_Chapter>(x => x.ID == chapterId).FirstOrDefault(); model.Title = chapter != null ? chapter.Name + "章节练习" + model.AddTime.ToString("yyyyMMddHHmmssfff") : "未知章节练习"; model.Source = model.QuestionStore_ID + "_" + chapterId + "_" + questionType + "_" + questionCount + "_" + questionSource + "_" + model.StuId; int practiceId = (int)Orm.Insert <W_ChapterPractice>(model, true); //第二步,创建明细表w_chapterpractice_detail foreach (Question q in list) { Orm.Insert <W_ChapterPractice_Detail>(new W_ChapterPractice_Detail() { ChapterPractice_ID = practiceId, Question_ID = q.ID }); q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null; } // 第三步,创建学生做题记录主表,保存开始做题时间 W_DoExamResult result = new W_DoExamResult(); result.StuId = model.StuId; result.BusType = 1;//章节练习 result.BusID = practiceId; result.BeginTime = model.AddTime; result.EndTime = model.AddTime; int resultId = (int)Orm.Insert <W_DoExamResult>(result, true); rtn.practiceId = practiceId; rtn.resultId = resultId; rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList(); } return(rtn); }
/// <summary> /// 获取本站点课程设置的数据[系统配置通用] /// </summary> /// <param name="System_Station_ID"></param> /// <returns></returns> public W_Configuration GetWConfiguration(int System_Station_ID) { return(Orm.Single <W_Configuration>(x => x.System_Station_ID == System_Station_ID)); }
public HackandCraftController() { orm = new Orm(); }
public void Orm_ShouldcreateValidSql_SimpleSelectAll() { var sql = new Orm().From("table").BuildQuery(); Assert.AreEqual("SELECT * FROM table", sql.Sql); }
public BaseContext(DbContextOptions options) { //开启一对多,级联保存功能 Orm.SetDbContextOptions(x => x.EnableAddOrUpdateNavigateList = true); }
public void Orm_ShouldcreateValidSql_MultipleOrders() { var sql = new Orm().From("table").Where(new Where("columnName", "abc")).OrderBy("column1").OrderByDesc("column2").BuildQuery(); Assert.AreEqual("SELECT * FROM table WHERE columnName = @param0 ORDER BY column1 ASC, column2 DESC", sql.Sql); }
public void Orm_ShouldcreateValidSql_Select_Raws() { var sql = new Orm().Select(Select.Raw("getDate()"), Select.Raw("'abd'")).BuildQuery(); Assert.AreEqual("SELECT getDate() as getDate, 'abd' as abd", sql.Sql); }
public void Orm_ShouldcreateValidSql_Select_RawNamed() { var sql = new Orm().Select(Select.Raw("getDate()", "date")).BuildQuery(); Assert.AreEqual("SELECT getDate() as date", sql.Sql); }
/// <summary> /// 获取订单信息 hx add /// </summary> /// <param name="orderId"></param> /// <returns></returns> public dynamic GetOrderById(string orderId) { return(Orm.Single <W_Order>(x => x.OrderId == orderId)); }
public void Orm_ShouldcreateValidSql_Select_dangerousNames() { var sql = new Orm().Select("abc, *").BuildQuery(); }
/// <summary> /// 修改老师 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool TeacherUpdate(TeacherModel model) { if (model.System_Station_ID == 0) { throw new ApiException("机构ID不存在!"); } if (model.TeacherDetail_ID == 0) { throw new ApiException("TeacherDetail_ID不能为空!"); } if (string.IsNullOrEmpty(model.Name)) { throw new ApiException("姓名不能为空!"); } if (string.IsNullOrEmpty(model.CardNo)) { //throw new ApiException("身份证不能为空!"); } else { string CardNumRegexStr = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)"; if (!Regex.IsMatch(model.CardNo, CardNumRegexStr)) { throw new ApiException("身份证格式不正确!"); } } //根据老师详细ID查询老师 TeacherModel teacherModel = SqlMapper.QueryForObject <TeacherModel>("GetTeacherByWhere", new { CardNo = "", Phone = "", System_Station_ID = model.System_Station_ID, TeacherDetail_ID = model.TeacherDetail_ID }); if (teacherModel == null) { throw new ApiException("老师不存在,TeacherDetail_ID是否正确!"); } //如果身份证有变更 if ((!string.IsNullOrEmpty(model.CardNo)) && model.CardNo != teacherModel.CardNo) { //判断身份证是否已使用 T_TeacherInfo teacher = SqlMapper.QueryForObject <T_TeacherInfo>("GetTeacherByCardOrPhone", new { CardNo = model.CardNo, Phone = "" }); if (teacher != null) { throw new ApiException("身份证已存在,姓名为:" + teacher.Name); } } //如果手机号有变更 if (model.Phone != teacherModel.Phone) { //判断身份证是否已使用 T_TeacherInfo teacher = SqlMapper.QueryForObject <T_TeacherInfo>("GetTeacherByCardOrPhone", new { CardNo = "", Phone = model.Phone }); if (teacher != null) { throw new ApiException("手机号已存在,姓名为:" + teacher.Name); } } bool update = false; try { SqlMapper.BeginTransaction();//开启事务 int updateTeacher = SqlMapper.Update("TeacherUpdate", new { Name = model.Name, Sex = model.Sex, CardNo = model.CardNo, JobTitle = model.JobTitle, HeadImage = model.HeadImage, Phone = model.Phone, Email = model.Email, Birthday = model.Birthday, Address = model.Address, Education_ID = model.Education_ID, GraduateSchool = model.GraduateSchool, Introduction = model.Introduction, ID = model.ID, System_Station_ID = model.System_Station_ID }); if (updateTeacher > 0) { //删除老师学科关系 SqlMapper.Delete("DeleteTeacherDiscipline", new { TeacherDetail_ID = model.TeacherDetail_ID, System_Station_ID = model.System_Station_ID }); //添加老师学科关系 if (model.Teacher_DisciplineIds != null && model.Teacher_DisciplineIds.Length > 0) { string[] dics = model.Teacher_DisciplineIds.Split(','); if (dics.Length > 0) { T_TeacherInfo_Detail_Discipline teacherD_Dis = null; foreach (string disciplineId in dics) { if (string.IsNullOrEmpty(disciplineId)) { continue; } teacherD_Dis = new T_TeacherInfo_Detail_Discipline(); teacherD_Dis.TeacherDetail_ID = model.TeacherDetail_ID; teacherD_Dis.System_Station_ID = model.System_Station_ID; teacherD_Dis.Discipline_ID = int.Parse(disciplineId); teacherD_Dis.AddTime = model.AddTime; teacherD_Dis.AddPerson = model.AddPerson; //添加老师所教学科 Orm.Insert(teacherD_Dis); } } } update = true; } else { throw new ApiException("修改老师信息失败!"); } SqlMapper.CommitTransaction(); } catch (Exception ex) { SqlMapper.RollBackTransaction(); throw new ApiException(ex.Message); } finally { //SqlMapper.CloseConnection(); } return(update); }
/// <summary> /// 插入 同步 集合 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entitys"></param> /// <returns></returns> public int UowInsert <T>(IEnumerable <T> entitys) where T : class { return(Orm.Insert(entitys).WithTransaction(UnitOfWork.GetOrBeginTransaction()).ExecuteAffrows()); }
/// <summary> /// 添加老师 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool TeacherInsert(TeacherModel model) { bool add = false; if (model.System_Station_ID == 0) { throw new ApiException("机构ID不存在!"); } if (string.IsNullOrEmpty(model.Name)) { throw new ApiException("姓名不能为空!"); } if (string.IsNullOrEmpty(model.CardNo)) { //throw new ApiException("身份证不能为空!"); } else { string CardNumRegexStr = "(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)"; if (!Regex.IsMatch(model.CardNo, CardNumRegexStr)) { throw new ApiException("身份证格式不正确"); } //查询老师身份证是否存在 TeacherModel teacherModel = SqlMapper.QueryForObject <TeacherModel>("GetTeacherByWhere", new { CardNo = model.CardNo, Phone = "", System_Station_ID = model.System_Station_ID, TeacherDetail_ID = 0 }); if (teacherModel != null) { throw new ApiException("身份证为" + model.CardNo + "的老师已存在,姓名为" + teacherModel.Name); } } //查询老师手机号码是否存在 TeacherModel PhoneModel = SqlMapper.QueryForObject <TeacherModel>("GetTeacherByWhere", new { CardNo = "", Phone = model.Phone, System_Station_ID = model.System_Station_ID, TeacherDetail_ID = 0 }); if (PhoneModel != null) { throw new ApiException("电话号码为" + model.Phone + "的老师已存在,姓名为" + PhoneModel.Name); } try { SqlMapper.BeginTransaction();//开启事务 //根据身份证查询老师主表 T_TeacherInfo teacher = null; if (!string.IsNullOrEmpty(model.CardNo)) { teacher = SqlMapper.QueryForObject <T_TeacherInfo>("GetTeacherByCardOrPhone", new { CardNo = model.CardNo, Phone = "" }); } //根据手机号码查询老师主表 T_TeacherInfo teacher2 = SqlMapper.QueryForObject <T_TeacherInfo>("GetTeacherByCardOrPhone", new { CardNo = "", Phone = model.Phone }); if (teacher == null && teacher2 == null) //主表没有,插入主表 { T_TeacherInfo teacher3 = new T_TeacherInfo(); teacher3.Name = model.Name; teacher3.Sex = model.Sex; teacher3.CardNo = model.CardNo; teacher3.JobTitle = model.JobTitle; teacher3.HeadImage = model.HeadImage; teacher3.Phone = model.Phone; teacher3.Email = model.Email; teacher3.Birthday = model.Birthday; teacher3.Address = model.Address; teacher3.Education_ID = model.Education_ID; teacher3.GraduateSchool = model.GraduateSchool; teacher3.Introduction = model.Introduction; teacher3.AddPerson = model.AddPerson; teacher3.AddTime = model.AddTime; int id = (int)Orm.Insert(teacher3, true); if (id > 0) { //添加主表成功,添加子表 model.ID = id; add = InsertTeacherDetail(model); } else { throw new ApiException("添加老师主表失败!"); } } else //主表有,插入子表 { if (teacher != null && teacher2 != null) { //如果是同一主表 if (teacher.ID == teacher2.ID) { model.ID = teacher.ID; } else { //不是同一主表,以身份证为主表 model.ID = teacher.ID; model.CardNo = ""; //不更新身份证 model.Phone = ""; //不更新号码 } } else if (teacher != null && teacher2 == null) { model.ID = teacher.ID; } else if (teacher == null && teacher2 != null) { model.ID = teacher2.ID; } int updateTeacher = SqlMapper.Update("TeacherUpdate", new { Name = model.Name, Sex = model.Sex, CardNo = model.CardNo, JobTitle = model.JobTitle, HeadImage = model.HeadImage, Phone = model.Phone, Email = model.Email, Birthday = model.Birthday, Address = model.Address, Education_ID = model.Education_ID, GraduateSchool = model.GraduateSchool, Introduction = model.Introduction, ID = model.ID, //System_Station_ID = model.System_Station_ID }); if (updateTeacher > 0) //修改主表 { //添加子表 add = InsertTeacherDetail(model); } } SqlMapper.CommitTransaction(); } catch (Exception ex) { SqlMapper.RollBackTransaction(); throw new ApiException(ex.Message); } finally { //SqlMapper.CloseConnection(); } return(add); }
private bool getElvDetails() { bool ret = false; var orm = new Orm(new MSSQLData()); var result = orm.execObject<Result>(payment,"api.get_elv_details"); if (result.dbMessage == "INVALID_SORT_CODE") { paymentStatus.success = false; paymentStatus.message = result.dbMessage; } else { payment.bankName = result.Payment.bankName; payment.bankLocation = result.Payment.bankLocation; ret = true; } return ret; }
public IEnumerable <HistoricalRoute> GetHistoricalPageLocations(Site site) { var sqlFilter = SqlFilter.FromEntityFilter("SiteId == {" + site.ContentId + "}", typeof(HistoricalRoute)); return(Orm.FindUnversionedContent <HistoricalRoute>(sqlFilter).Result); }
internal static void setMessage(MessageStatus messageStatus) { var connstr = Config.Instance.dbConn; var orm = new Orm(new MSSQLData(connstr)); orm.execObject<Result>(messageStatus, "mess.set_message_status"); }
/// <summary> /// 交卷 /// </summary> /// <param name="model"></param> /// <param name="stuId"></param> /// <returns></returns> public bool SubmitPractice(PracticeModel model, string stuId) { W_DoExamResult result = Orm.Select <W_DoExamResult>(x => x.ID == model.resultId).FirstOrDefault(); if (result == null) { throw new ApiException("对象错误"); } else if (string.IsNullOrEmpty(stuId) || result.StuId != stuId) { throw new ApiException("登陆超时,请重新登陆"); } result.EndTime = DateTime.Now; result.Valid = 1;//交卷 SqlMapper.BeginTransaction(); try { //获取试卷题型对应的分数 List <W_ExamPaperDetail> detailList = null; if (result.BusType == 0)//试卷模式 { //更新试卷测试次数 W_ExamPaper paper = Orm.Single <W_ExamPaper>(x => x.ID == result.BusID); paper.DoCount += 1; Orm.Update <W_ExamPaper>(paper); //试卷题型对应得分 detailList = Orm.Select <W_ExamPaperDetail>(x => x.ExamPaper_ID == result.BusID).ToList(); } else//更改章节练习状态 { W_ChapterPractice cp = Orm.Single <W_ChapterPractice>(x => x.ID == result.BusID); cp.Status = 1; Orm.Update <W_ChapterPractice>(cp); } //保存做题记录明细 foreach (Question question in model.list) { decimal sorce = 0; if (result.BusType == 0)//试卷模式 { W_ExamPaperDetail temp = detailList.FirstOrDefault(x => x.QuestionType_ID == question.QuestionType_ID); sorce = temp != null ? temp.Sorce : 0; } Orm.Insert <W_DoExamResult_Detail>(new W_DoExamResult_Detail() { DoExamResult_ID = result.ID, Question_ID = question.ID, StuID = result.StuId, MyAnswer = question.MyAnswer, Judge = question.Judge, Sorce = sorce, UpdateTime = result.EndTime }); //更新题目信息 SqlMapper.Update("UpdateQuestion", new { ID = question.ID, Judge = question.Judge, EasyWrongAnswer = question.MyAnswer }); } //修改做题记录主表 Orm.Update <W_DoExamResult>(result); SqlMapper.CommitTransaction(); } catch { SqlMapper.RollBackTransaction(); return(false); } return(true); }