public JsonResult insert([FromBody] test obj) { var msg = new JMessage() { Error = false }; try { var query = from a in _context.edu_student where a.code == obj.code select a; if (query.Count() == 0) { edu_student obj1 = new edu_student(); obj1.code = obj.code; obj1.firstname = obj.firstname; obj1.sex = obj.sex; // obj1.Birthday = Convert.ToDateTime(obj.Birthday); obj1.birthday = obj.birthday; obj1.flag = 1; obj1.createtime = DateTime.Now; _context.edu_student.Add(obj1); _context.SaveChanges(); edu_student_contact obj2 = new edu_student_contact(); var rs = _context.edu_student.OrderByDescending("id").FirstOrDefault(); obj2.studentID = rs.id; obj2.flag = 1; obj2.relationship = obj.relationship; obj2.name = obj.name; _context.edu_student_contact.Add(obj2); _context.SaveChanges(); msg.Title = "Thêm thành công"; } else { msg.Error = true; msg.Title = "Mã đã tồn tại"; } } catch (Exception ex) { msg.Error = true; msg.Object = ex; msg.Title = "Có lỗi khi thêm "; } return(Json(msg)); }
public JsonResult insert([FromBody] edu_student_contact obj) { var msg = new JMessage() { Error = false }; try { edu_student_contact obj1 = new edu_student_contact(); obj1.name = obj.name; obj1.company = obj.company; obj1.telephone = obj.telephone; obj1.career = obj.career; obj1.mobilephone = obj.mobilephone; obj1.email = obj.email; obj1.relationship = obj.relationship; obj1.address = obj.address; obj1.note = obj.note; obj1.position = obj.position; obj1.address = obj.address; obj1.note = obj.note; obj1.studentID = 4; obj1.flag = 1; _context.edu_student_contact.Add(obj1); _context.SaveChanges(); msg.Title = "Thêm thành công"; } catch (Exception ex) { msg.Error = true; msg.Object = ex; msg.Title = "Có lỗi khi thêm "; } return(Json(msg)); }
public JsonResult update([FromBody] edu_student_contact obj) { var msg = new JMessage() { Error = true }; try { edu_student_contact_history his = new edu_student_contact_history(); var rs1 = _context.edu_student_contact.SingleOrDefault(x => x.id == obj.id); var rs = _context.edu_student_contact.SingleOrDefault(x => x.id == obj.id); if (rs != null) { rs.id = obj.id; rs.name = obj.name; rs.company = obj.company; rs.telephone = obj.telephone; rs.mobilephone = obj.mobilephone; rs.email = obj.email; rs.relationship = obj.relationship; rs.address = obj.address; rs.note = obj.note; rs.studentID = obj.studentID; rs.position = obj.position; rs.career = obj.career; _context.edu_student_contact.Update(rs); if (rs1.name != obj.name) { his.date_change = DateTime.Now; his.column_change = "name"; his.old_value = rs1.name; his.old_value = obj.name; his.edu_student_contact_id = obj.id; _context.edu_student_contact_history.Add(his); } if (rs1.company != obj.company) { his.date_change = DateTime.Now; his.column_change = "company"; his.old_value = rs1.company; his.old_value = obj.company; his.edu_student_contact_id = obj.id; _context.edu_student_contact_history.Add(his); } if (rs1.telephone != obj.telephone) { his.date_change = DateTime.Now; his.column_change = "telephone"; his.old_value = rs1.telephone; his.old_value = obj.telephone; his.edu_student_contact_id = obj.id; _context.edu_student_contact_history.Add(his); } if (rs1.mobilephone != obj.mobilephone) { his.date_change = DateTime.Now; his.column_change = "mobilephone"; his.old_value = rs1.mobilephone; his.old_value = obj.mobilephone; his.edu_student_contact_id = obj.id; _context.edu_student_contact_history.Add(his); } if (rs1.email != obj.email) { his.date_change = DateTime.Now; his.column_change = "email"; his.old_value = rs1.email; his.old_value = obj.email; his.edu_student_contact_id = obj.id; _context.edu_student_contact_history.Add(his); } if (rs1.relationship != rs.relationship) { his.date_change = DateTime.Now; his.column_change = "relationship"; his.old_value = rs1.relationship.ToString(); his.old_value = obj.relationship.ToString(); his.edu_student_contact_id = obj.id; _context.edu_student_contact_history.Add(his); } if (rs1.address != obj.address) { his.date_change = DateTime.Now; his.column_change = "address"; his.old_value = rs1.address; his.old_value = obj.address; his.edu_student_contact_id = obj.id; _context.edu_student_contact_history.Add(his); } if (rs1.note != obj.note) { his.date_change = DateTime.Now; his.column_change = "note"; his.old_value = rs1.note; his.old_value = obj.note; his.edu_student_contact_id = obj.id; _context.edu_student_contact_history.Add(his); } if (rs1.position != rs.position) { his.date_change = DateTime.Now; his.column_change = "position"; his.old_value = rs1.position.ToString(); his.old_value = obj.position.ToString(); his.edu_student_contact_id = obj.id; _context.edu_student_contact_history.Add(his); } if (rs1.career != rs.career) { his.date_change = DateTime.Now; his.column_change = "career"; his.old_value = rs1.career.ToString(); his.old_value = obj.career.ToString(); his.edu_student_contact_id = obj.id; _context.edu_student_contact_history.Add(his); } _context.SaveChanges(); msg.Title = "Cập nhật thông tin thành công"; msg.Error = false; } } catch (Exception ex) { msg.Object = ex; msg.Title = "Có lỗi khi cập nhật"; } return(Json(msg)); }