public bool Commit() { try { _context.SaveChanges(); return(true); } catch (Exception ex) { //try //{ // // lưu lại log lỗi // string file = $@"\Logs_test_102"; // string filePath = _hostingEnvironment.WebRootPath + file; // if (!Directory.Exists(filePath)) // { // Directory.CreateDirectory(filePath); // } // filePath += $@"\ErrorSaveDataToDB.txt"; // using (StreamWriter writer = new StreamWriter(filePath, true)) // { // writer.WriteLine("-----------------------------------------------------------------------------"); // writer.WriteLine("Date : " + DateTime.Now.ToString()); // writer.WriteLine(); // while (ex != null) // { // writer.WriteLine(ex.GetType().FullName); // writer.WriteLine("Message : " + ex.Message); // writer.WriteLine("StackTrace : " + ex.StackTrace); // ex = ex.InnerException; // } // } //} //catch { } return(false); } }
public T AddReturn(T entity) { _context.Set <T>().Add(entity); _context.SaveChanges(); return(entity); }