public void process(Model.ServiceRequest request, Model.ServiceResponse response) { if (request == null || request.requestObj == null) { response.errMessage = ReportServiceMessage.REQUEST_INVALID; response.returnCode = -1; return; } UpdateTravelDiaryRequest serviceRequest = (UpdateTravelDiaryRequest)request.requestObj; if (serviceRequest.diary.userId < 0 || serviceRequest.diary.diaryId < 0) { response.errMessage = ReportServiceMessage.USER_ID_OR_DIARY_ID_INVALID; response.returnCode = -1; return; } diary d = new diary(); d.content = serviceRequest.diary.content; d.tag = serviceRequest.diary.tags; d.title = serviceRequest.diary.title; d.diaryID = (int)serviceRequest.diary.diaryId; Diary.updateDiary((int)serviceRequest.diary.diaryId, d); response.returnCode = 0; }
//PutTravelDiary 发布旅行日志 public static int saveDiary(diary diary) { using (var ctx = new hackthonEntities()) { ctx.AddTodiaries(diary); ctx.SaveChanges(); return diary.diaryID; } }
//updateTravelDiary 更新旅行日志 public static void updateDiary(int diaryID, diary updateddiary) { using (var ctx = new hackthonEntities()) { diary diary = getDiaryByDiaryID(diaryID); ctx.diaries.Attach(diary); if(diary.title !=updateddiary.title) diary.title =updateddiary.title; //todo: 写其他的 ctx.SaveChanges(); } }
/// <summary> /// Create a new diary object. /// </summary> /// <param name="diaryID">Initial value of the diaryID property.</param> public static diary Creatediary(global::System.Int32 diaryID) { diary diary = new diary(); diary.diaryID = diaryID; return diary; }
/// <summary> /// Deprecated Method for adding a new object to the diaries EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddTodiaries(diary diary) { base.AddObject("diaries", diary); }
public void process(ServiceRequest request, ServiceResponse response) { if (request == null || request.requestObj == null) { response.errMessage = ReportServiceMessage.REQUEST_INVALID; response.returnCode = -1; return; } PublishTravelDiaryRequest serviceRequest = (PublishTravelDiaryRequest)request.requestObj; if (serviceRequest.diary.userId < 0) { response.errMessage = ReportServiceMessage.USER_ID_ILLEGAL; response.returnCode = -1; return; } diary d = new diary(); d.title = serviceRequest.diary.title; d.userID = (int)serviceRequest.diary.userId; d.tag = serviceRequest.diary.tags; d.content = serviceRequest.diary.content; d.publishTime = DateTime.Now; int diaryId = Diary.saveDiary(d); MySqlConnection conn = ConnectionManager.getInstance().getConnection(); conn.Open(); string addr1 = null; string addr2 = null; string addr3 = null; if(serviceRequest.diary.addrs.Count > 0) { addr1 = serviceRequest.diary.addrs.ElementAt(0); } if(serviceRequest.diary.addrs.Count > 1) { addr2 = serviceRequest.diary.addrs.ElementAt(1); } if(serviceRequest.diary.addrs.Count > 2) { addr3 = serviceRequest.diary.addrs.ElementAt(2); } string sqlStr = String.Format("insert into diary_pic_info values ({0}, '{1}', '{2}', '{3}')", diaryId, addr1, addr2, addr3); MySqlCommand command = new MySqlCommand(); command.CommandText = sqlStr; command.Connection = conn; command.ExecuteNonQuery(); sqlStr = String.Format("update diary set categoryID={0} where diaryId={1}", serviceRequest.diary.belongCategory.categoryId, diaryId); command = new MySqlCommand(); command.CommandText = sqlStr; command.Connection = conn; command.ExecuteNonQuery(); conn.Close(); PublishTravelDiaryResponse serviceResoponse = new PublishTravelDiaryResponse(); serviceResoponse.diaryId = diaryId; response.responseObj = serviceResoponse; response.returnCode = 0; return; }