public FenLuItemDTO(FenLuItem fenlu) { this.ID = fenlu.ID; this.AgencyID = fenlu.AgencyID; this.ChapterID = fenlu.ChapterID; this.IsVipItem = fenlu.IsVipItem; this.Title = fenlu.Title; this.Image = fenlu.Image; this.Difficulty = fenlu.Difficulty; this.AddPerson = fenlu.AddPerson; this.AddTime = fenlu.AddTime; }
/// <summary> /// 添加分录题 /// </summary> public ServiceInvokeDTO AddFenLu(FenLuItem fenlu, List<FenLuAnswer> answers) { log.Debug(Constant.DEBUG_START); ServiceInvokeDTO result = null; try { fenluDAL.Insert(fenlu, answers); result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS); } catch (Exception ex) { log.Error(ex); throw ex; } log.Debug(Constant.DEBUG_END); return result; }
/// <summary> /// 更新分录题 /// </summary> public ServiceInvokeDTO UpdateFenLu(FenLuItem fenlu, List<FenLuAnswer> answers) { log.Debug(Constant.DEBUG_START); ServiceInvokeDTO result = null; try { FenLuItem dbFenlu = fenluDAL.GetByID(fenlu.ID); if (dbFenlu != null) { fenluDAL.Update(fenlu, answers); result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS); } else { result = new ServiceInvokeDTO(InvokeCode.SYS_OBJECT_NOT_EXIST_ERROR); } } catch (Exception ex) { log.Error(ex); throw ex; } log.Debug(Constant.DEBUG_END); return result; }
public ActionResult UpdateFenLu() { log.Debug(Constant.DEBUG_START); string idString = ApiQueryUtil.QueryArgByPost("id"); string isVipItemString = ApiQueryUtil.QueryArgByPost("is_vip_item"); 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 { FenLuItem fenlu = new FenLuItem(); fenlu.ID = Convert.ToInt32(idString); fenlu.IsVipItem = Convert.ToInt32(isVipItemString); fenlu.ChapterID = Convert.ToInt32(chapterIDString); fenlu.Title = title; fenlu.Difficulty = Convert.ToInt32(difficultyString); 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(); } fenlu.Image = imageBytes; } List<FenLuAnswer> answers = JsonConvert.DeserializeObject<List<FenLuAnswer>>(answersJsonString); AgencyAdminDTO currentAdmin = Session[Constant.SESSION_KEY_ADMIN] as AgencyAdminDTO; ServiceInvokeDTO checkResult = permissionService.CheckPermission(DoActionType.UpdateFenLu, currentAdmin.Agency.ID, fenlu.ID); if (checkResult.Code == InvokeCode.SYS_INVOKE_SUCCESS) { result = itemDataService.UpdateFenLu(fenlu, answers); } else { result = checkResult; } } 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); }
/// <summary> /// 更新实体信息 /// </summary> public void Update(FenLuItem fenlu, List<FenLuAnswer> answers) { const string update_item_sql = @"UPDATE FenLuItem SET ChapterID = @ChapterID, IsVipItem= @IsVipItem, Title= @Title, Image = @Image, Difficulty = @Difficulty WHERE IsDeleted = 0 AND ID = @ID"; const string delete_answer_sql = @"UPDATE FenLuAnswer SET IsDeleted = 1 WHERE FenLuItemID = @FenLuItemID"; const string insert_answer_sql = @"INSERT INTO FenLuAnswer(FenLuItemID, Answer, Annotation) VALUES (@FenLuItemID, @Answer, @Annotation);"; using (DbConnection connection = ConnectionManager.OpenConnection) { IDbTransaction transaction = connection.BeginTransaction(); try { connection.Execute(update_item_sql, fenlu, transaction); connection.Execute(delete_answer_sql, new { FenLuItemID = fenlu.ID }, transaction); foreach (var answer in answers) { connection.Execute(insert_answer_sql, new { FenLuItemID = fenlu.ID, Answer = answer.Answer, Annotation = answer.Annotation }, transaction ); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }
/// <summary> /// 添加实体信息,返回添加成功后的主键ID /// </summary> public void Insert(FenLuItem fenlu, List<FenLuAnswer> answers) { const string insert_item_sql = @"INSERT INTO FenLuItem(AgencyID, ChapterID, IsVipItem, Title, Image, Difficulty, AddPerson) VALUES (@AgencyID, @ChapterID, @IsVipItem, @Title, @Image, @Difficulty, @AddPerson); SELECT LAST_INSERT_ID();"; const string insert_answer_sql = @"INSERT INTO FenLuAnswer(FenLuItemID, Answer, Annotation) VALUES (@FenLuItemID, @Answer, @Annotation);"; using (DbConnection connection = ConnectionManager.OpenConnection) { IDbTransaction transaction = connection.BeginTransaction(); try { int fenluID = connection.Query<int>(insert_item_sql, fenlu, transaction).SingleOrDefault<int>(); foreach (var answer in answers) { connection.Execute(insert_answer_sql, new { FenLuItemID = fenluID, Answer = answer.Answer, Annotation = answer.Annotation }, transaction ); } transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }