public int Add(FeedBack model, out string error) { error = ""; if (model == null || string.IsNullOrEmpty(model.Title) || string.IsNullOrEmpty(model.Contents)) { error = "内容不能为空"; return(0); } if (model.Title.Length > 50 || model.Contents.Length > 300) { error = "反馈内容的字数超过范围"; return(0); } string ip = CommonCs.GetHostAddress(); t_feedback entity = new t_feedback() { contents = model.Contents, title = model.Title, from_ip = ip, from_area = BaiduIPAdressAPI.GetAddress(ip), create_time = DateTime.Now, status = FeedBackStatus.Unread, }; try { dbContext.t_feedback.Add(entity); dbContext.SaveChanges(); return(1); } catch (Exception ex) { error = ex.Message; return(0); } }
//SET TO DB public static ResponResultViewModel Save(FeedbackViewModel entity, long userid) { ResponResultViewModel res = new ResponResultViewModel(); try { using (var db = new MinProContext()) { if (entity.id == 0) { t_feedback feedback = new t_feedback(); feedback.version_id = entity.version_id; feedback.test_id = entity.test_id; feedback.json_feedback = entity.json_feedback; feedback.created_by = userid; feedback.created_on = DateTime.Now; feedback.is_delete = false; db.t_feedback.Add(feedback); db.SaveChanges(); res.Entity = feedback; } else { res.Success = false; res.Message = "Feedback Not Found"; } } } catch (Exception e) { res.Success = false; res.Message = e.Message; } return(res); }
public static ResponseResult Update(FeedbackViewModel entity) { ResponseResult result = new ResponseResult(); try { using (var db = new XBC_Context()) { //create if (entity.id == 0) { t_feedback fed = new t_feedback(); t_document_test_detail dtd = new t_document_test_detail(); fed.test_id = entity.test_id; fed.document_test_id = entity.document_test_id; var Serial = new JavaScriptSerializer(); object data = new { fed.test_id, fed.document_test_id, entity.Feedback }; var json = Serial.Serialize(data); //string a = data.ToString(); //string b; //foreach (var item in FeedbackRepo.ListDTD(entity.document_test_id)) //{ // //dtd.question_id = entity.question_id; // //answer = entity.answer; // object data2 = new // { // //dtd.question_id, // //answer // }; // b = data2.ToString(); // a = a + b; // json = Serial.Serialize(b); //} fed.json_feedback = json; fed.created_by = entity.UserId; fed.created_on = DateTime.Now; db.t_feedback.Add(fed); db.SaveChanges(); var json1 = new JavaScriptSerializer().Serialize(fed); t_audit_log log = new t_audit_log(); log.type = "Insert"; log.json_insert = json1; log.created_by = entity.UserId; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); //t_audit_log log = new t_audit_log(); //log.type = "Insert"; //log.json_insert = json; //log.created_by = 1; //log.created_on = DateTime.Now; //db.t_audit_log.Add(log); //db.SaveChanges(); entity.id = fed.id; result.Entity = entity; } else //edit { t_feedback fed = new t_feedback(); t_document_test_detail dtd = new t_document_test_detail(); fed.test_id = entity.test_id; fed.document_test_id = entity.id; var Serial = new JavaScriptSerializer(); object data = new { fed.test_id, fed.document_test_id }; var json = Serial.Serialize(""); string a = data.ToString(); string b; foreach (var item in FeedbackRepo.ListDTD(entity.id)) { //dtd.question_id = entity.question_id; //answer = entity.answer; object data2 = new { //dtd.question_id, //answer }; b = data2.ToString(); a = a + b; json = Serial.Serialize(b); } fed.json_feedback = json; fed.created_by = entity.UserId; fed.created_on = DateTime.Now; db.t_feedback.Add(fed); db.SaveChanges(); t_audit_log log = new t_audit_log(); log.type = "Insert"; log.json_insert = json; log.created_by = entity.UserId; log.created_on = DateTime.Now; db.t_audit_log.Add(log); db.SaveChanges(); entity.id = fed.id; result.Entity = entity; //} } } } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.Message; } return(result); }