예제 #1
0
        public bool Commit()
        {
            try
            {
                _context.SaveChanges();
                return(true);
            }
            catch (Exception)
            {
                //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);
            }
        }
예제 #2
0
 public T AddReturn(T entity)
 {
     _context.Add(entity);
     _context.SaveChanges();
     return(entity);
 }