public BlankItemDTO(BlankItem blankItem) { this.ID = blankItem.ID; this.ChapterID = blankItem.ChapterID; this.Title = blankItem.Title; this.Image = blankItem.Image; this.Difficulty = blankItem.Difficulty; this.AddPerson = blankItem.AddPerson; this.AddTime = blankItem.AddTime; }
/// <summary> /// 添加填空题 /// </summary> public ServiceInvokeDTO AddBlank(BlankItem blank, List<BlankAnswer> answers) { log.Debug(Constant.DEBUG_START); ServiceInvokeDTO result = null; try { blankDAL.Insert(blank, answers); result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS); } catch (Exception ex) { log.Error(ex); throw ex; } log.Debug(Constant.DEBUG_END); return result; }
public ActionResult AddBlank() { log.Debug(Constant.DEBUG_START); string chapterIDString = ApiQueryUtil.QueryArgByPost("chapter_id"); string title = ApiQueryUtil.QueryArgByPost("title"); HttpPostedFileBase imageFile = Request.Files["image"]; string difficultyString = ApiQueryUtil.QueryArgByPost("difficulty"); string answersJsonString = ApiQueryUtil.QueryArgByPost("answers"); ServiceInvokeDTO result = null; try { BlankItem blank = new BlankItem(); blank.ChapterID = Convert.ToInt32(chapterIDString); blank.Title = title; blank.Difficulty = Convert.ToInt32(difficultyString); blank.AddPerson = (Session[Constant.SESSION_KEY_ADMIN] as Teacher).ChineseName; if (imageFile != null) { byte[] imageBytes = null; using (Stream inputStream = imageFile.InputStream) { MemoryStream memoryStream = inputStream as MemoryStream; if (memoryStream == null) { memoryStream = new MemoryStream(); inputStream.CopyTo(memoryStream); } imageBytes = memoryStream.ToArray(); } blank.Image = imageBytes; } List<BlankAnswer> answers = JsonConvert.DeserializeObject<List<BlankAnswer>>(answersJsonString); result = itemDataService.AddBlank(blank, answers); } catch (Exception ex) { log.Error(ex); result = new ServiceInvokeDTO(InvokeCode.SYS_INNER_ERROR); } string json = JsonConvert.SerializeObject(result, Formatting.Indented, Constant.TIME_CONVERTER); log.Debug(Constant.DEBUG_END); return Content(json, Constant.JSON_MIME_TYPE); }
public BlankItemDTO(BlankItem blankItem, List<BlankAnswer> answers) : this(blankItem) { this.Answers = answers; }
/// <summary> /// 更新实体信息 /// </summary> public void Update(BlankItem blankItem, List<BlankAnswer> answers) { const string update_item_sql = @"UPDATE BlankItem SET ChapterID = @ChapterID,Title= @Title, Image = @Image, Difficulty = @Difficulty WHERE IsDeleted = 0 AND ID = @ID"; const string delete_answer_sql = @"UPDATE BlankAnswer SET IsDeleted = 1 WHERE BlankItemID = @BlankItemID"; const string insert_answer_sql = @"INSERT INTO BlankAnswer(BlankItemID, AnswerIndex, Answer, Annotation) VALUES (@BlankItemID, @AnswerIndex, @Answer, @Annotation);"; using (DbConnection connection = ConnectionManager.OpenConnection) { IDbTransaction transaction = connection.BeginTransaction(); try { connection.Execute(update_item_sql, blankItem, transaction); connection.Execute(delete_answer_sql, new { BlankItemID = blankItem.ID }, transaction); foreach (var answer in answers) { connection.Execute(insert_answer_sql, new { BlankItemID = blankItem.ID, AnswerName = answer.AnswerIndex, Answer = answer.Answer, Annotation = answer.Annotation }, transaction ); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }
/// <summary> /// 添加实体信息,返回添加成功后的主键ID /// </summary> public void Insert(BlankItem numberBlankItem, List<BlankAnswer> answers) { const string insert_item_sql = @"INSERT INTO BlankItem(ChapterID, Title, Image, Difficulty, AddPerson) VALUES (@ChapterID, @Title, @Image, @Difficulty, @AddPerson); SELECT LAST_INSERT_ID();"; const string insert_answer_sql = @"INSERT INTO BlankAnswer(BlankItemID, AnswerIndex, Answer, Annotation) VALUES (@BlankItemID, @AnswerIndex, @Answer, @Annotation);"; using (DbConnection connection = ConnectionManager.OpenConnection) { IDbTransaction transaction = connection.BeginTransaction(); try { int numberBlankID = connection.Query<int>(insert_item_sql, numberBlankItem, transaction).SingleOrDefault<int>(); foreach (var answer in answers) { connection.Execute(insert_answer_sql, new { NumberBlankItemID = numberBlankID, AnswerName = answer.AnswerIndex, Answer = answer.Answer, Annotation = answer.Annotation }, transaction ); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }